0

我在这里遇到了一些问题。基本上,我想比较列。所以我获取了对象,比较结果正如预期的那样出现。但是,在我添加 fetch_array 以查看当前表希望比较值出现在比较值旁边之后,它不再返回比较值。有什么办法可以运行比较代码并让它出现在表格中?我尝试了一个查询,但它只适用于 MySQL 而不是 PHP。

$query = "SELECT * FROM system_audit"; $result = mysql_query($query) or die(mysql_error());

echo " ID Type Setting Value ";

while($row = mysql_fetch_array($result)) { 

   echo  $row['ID']; 
   echo  $row['Type']; 
   echo  $row['Setting']; 
   echo  $row['Value'];       
}  

while ($row = mysql_fetch_object($result)) { 
    if($row->Setting != $row->Value) { 

        echo "X";
    } else { 
        echo "O"; 

    } 
}
4

1 回答 1

0

Your code contains a lot of echo's that have no use. I would suggest learning PHP a bit more.

Your compare is wrong, this should work :

$query = "SELECT * FROM system_audit"; 
$result = mysql_query($query) or die(mysql_error());

echo " ID Type Setting Value ";

while($row = mysql_fetch_array($result)) { 
   echo $row['ID'] . "<br>"; 
   echo $row['Type'] . "<br>"; 
   echo $row['Setting'] . "<br>"; 
   echo $row['Value'] . "<br>"; 

   if($row['Setting'] != $row['Value']) { 
        echo "X" . "<br>";
    } 
    else { 
        echo "O" . "<br>";
} 
echo "<br>";
于 2012-09-06T09:08:29.933 回答