您在 之后关闭了 while 循环$value_system
。这意味着将获取并存储所有记录$name_system
,$value_system
但循环将覆盖先前的变量,因此只有最后一条记录存储在该变量中。
这似乎是一个不完整的代码。您可以做的是将右大括号移到您希望为每条记录执行的过程的末尾。
$result = mysql_query("SELECT * FROM system") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$name_system = $row['name'];
$value_system = $row['value'];
} // you closed the WHILE loop here.
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;
我想你的代码是这样的:
$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;
// my imagination i was talking about:
if ($offline_system) echo 'The system is offline<br />';
else echo 'The system is online<br />';
if ($register_system) echo 'The registration is online<br />';
else echo 'The registration system is offline';
} // curly brace MOVED.