下面的简单查询不返回任何结果。我看不到任何错误。知道为什么它不起作用吗?
$sqlStr3 = "SELECT loginid,
username,
created
FROM login
ORDER BY created DESC
LIMIT 200";
$result = mysql_query($sqlStr3);
$count = 1;
$arr = array();
echo "<table class=\"samplesrec1edit\">";
while ($row = mysql_fetch_array($result)) {
$dt = new DateTime($row["created"], $tzFrom);
$dt->setTimezone($tzTo);
echo '<tr>';
echo '<td class="sitename1edit2a">'.$count++.'.</td>';
echo '<td class="sitename1edit1"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.stripslashes($row["username"]).'</a></td>';
echo '<td class="sitename1edit2">'.$dt->format('F j, Y &\nb\sp &\nb\sp g:i a').'</td>';
echo '</tr>';
}
echo "</table>";
最佳答案
将查询行从以下位置更改:
$result = mysql_query($sqlStr3);
至
$result = mysql_query($sqlStr3) or die("MySQL error: " . mysql_error());
即使查询本身看起来不错,也有数不胜数的原因会导致其他问题。
如果尚未打开,请打开PHP的display_errors并执行
error_reporting(E_ALL)
。可能查询部分很好,并且其他内容正在爆炸(例如,$tzFrom
中的无效值)。关于php - 简单查询不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4019317/