So I want to get some data from mysql and use it to create some conditions. Here is my code, but it only shows the last record from mysql.
$result = mysql_query("SELECT * FROM system") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$name_system = $row['name'];
$value_system = $row['value'];
}
if($name_system=='website_register' AND $value_system==1)
$register_system = 1;
else
$register_system = 0;
if($name_system=='website_offline' AND $value_system==1)
$offline_system = 1;
else
$offline_system = 0;
Then if I’m trying to echo “$offline_system” or “$register_system” in another page, it dosen’t show the true data.
You closed the while loop after
$value_system. This means all records will be fetched and stored in$name_systemand$value_systembut the loop will overwrite the previous variable so only the last record is stored in that variable.This seems to be an incomplete code. What you can do is move that closing brace further down the end of the procedure you are expecting to do for each record.
I imagine your code to be something like this: