我有一个小型数据库,将显示数据更新为0而不是1.当我尝试运行以下sql查询时
数据库PHP //连接到数据库 $主机= “localhost” 的; $数据库= “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
}
?>
答案 0 :(得分:1)
查询语法错误尝试:
$query = "SELECT * FROM mods ORDER BY id where updated='0'";
答案 1 :(得分:1)
请尝试这些并检查哪一个适合您: -
正如@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子句。