我有奇怪的问题,在我执行搜索后重命名(并在查询时更新)MySQL表我收到此警告:
警告:mysql_result()[function.mysql-result]:无法跳转到第94行D:\ dev \ search.php中MySQL结果索引8的第0行
这是我的代码:
$query = "SELECT * FROM admin WHERE ((`status_desc` LIKE '%".$search."%') OR ('%".$search."%')) LIMIT 100";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_numrows($result);
第94行是$status_id
:
<?php
$i=0;
while ($i < $num)
{
$status_id = mysql_result($result,$i,"status_id");
$status_des = mysql_result($result,$i,"status_desc");
?>
<tr>
<td><a href="config_status_edit.php?status_id=<?php echo $status_id; ?>"><?php echo $status_id; ?></a></td>
<td><?php echo $status_desc; ?></td>
</tr>
<?php
$i++;
}
?>
怎么了? (我已计划更新到PDO,但现在我需要使用mysql_query)
答案 0 :(得分:0)
使用mysql_fetch_ *函数代替mysql_result
$query = "SELECT * FROM admin WHERE ((`status_desc` LIKE '%".$search."%') OR ('%".$search."%')) LIMIT 100";
$result = mysql_query($query) or die(mysql_error());
while ( ($row=mysql_fetch_assoc($result)) ) {
$status_id = $row["status_id"];
$status_des = $row["status_desc"];
?>
<tr>
<td>
<a href="config_status_edit.php?status_id=<?php echo $status_id; ?>">
<?php echo $status_id; ?>
</a>
</td>
<td><?php echo $status_desc; ?></td>
</tr>
<?php
}
它将循环直到它没有更多的行来获取,不需要设置/检查计数器等。
答案 1 :(得分:0)
验证$num
if ($num > 0) {
echo "rows found";
} else {
echo "none found";
}
WHERE (`status_desc` LIKE '%".$search."%' OR `status_desc`LIKE '%".$othersearch."%')
WHERE (`status_desc` LIKE '%".$search."%' OR `other_column`LIKE '%".$search."%')
在sql客户端运行您的查询我怀疑这是问题所在。