我有一个小型数据库,它将显示更新为 0 而不是 1 的数据。当我尝试运行以下 sql 查询时
数据库PHP //连接到数据库 $主机名=“本地主机”; $数据库=“xxxx”; $用户名="xxxxx"; $密码="xxxxx";
@$conn = mysqli_connect($hostname, $username, $password)
or die("Could not connect to server " . mysql_error());
mysqli_select_db($conn, $database)
or die("Error: Could not connect to the database: " . mysql_error());
/*Check for Connection*/
if(mysqli_connect_errno()){
// Display Error message if fails
echo 'Error, could not connect to the database please try again again.';
exit();
}
$query = 'SELECT * FROM mods ORDER BY id where updated="0"';
$result = mysqli_query($conn, $query);
@$num_results = mysqli_num_rows($result);
我试过将 0 换行和不换行在 '' 和 ""中。
目前它只加载没有数据的 HTML 表格。如果我删除 where 语句,它会很好。
HTML PHP
for($i=0; $i<$num_results; $i++) {
$row = mysqli_fetch_assoc($result);
?>
<tr>
<td style=""><?php print $row['mod_name']; ?></td>
<td style=""><div id"tdcenter" style="width: 44px;white-space:nowrap;overflow: hidden;text-overflow: ellipsis;text-align:center;"><?php print $row['mod_version']; ?></div></td>
<td style=""><?php print $row['time']; ?></td>
</tr>
<?php
// end loop
}
?>
最佳答案
请尝试这些并检查哪一个适合您:-
正如@BigRabbit 所说:- $query = "SELECT * FROM mods ORDER BY id where updated='0'";
创建变量 $update = 0; 现在将其附加到您的查询 $query = "SELECT * FROM mods ORDER BY id where updated=".$update;
另一种尝试是交换 ORDERBY 和 WHERE 子句。
关于php - 无法获取等于 0 的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30146957/