<select name="fname">
<?php
$resultTable = mysql_query("SHOW TABLES");
while($row = mysql_fetch_array($resultTable)){
echo "<option value=$row[0]>".$row[0]."</option>";
</select>
}
<?php
$name = $_REQUEST['fname'];
$length=3;
$pagenum=@$_GET['page']?$_GET['page']:1;
$sqltot="select count(*) from $name";
$arrtot=mysql_fetch_row(mysql_query($sqltot));
$pagetot=ceil($arrtot[0]/$length);
if($pagenum>=$pagetot){
$pagenum=$pagetot;
}
$offset=($pagenum-1)*$length;
$sql = "SELECT * FROM $name LIMIT {$offset},{$length}";
$result = mysql_query($sql);
echo "<table width='700px' border='1px'>";
while($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>{$row['num1']}</td>";
echo "<td>{$row['num2']}</td>";
echo "<td>{$row['num3']}</td>";
echo "</tr>";
}
echo "</table>";
$prevpage=$pagenum-1;
$nextpage=$pagenum+1;
echo "<h2><a href='showdata.php?page={$prevpage}'>上一页</a><a href='showdata.php?page={$nextpage}'>下一页</a></h2>";
mysql_close($conn);
?>
第一页还能正确的分页并显示数据,一按下一页就出错了:
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in D:ServerWebshowdata.php on line 57
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in D:ServerWebshowdata.php on line 67
这是怎么回事啊???
麻烦各位大神看看~谢谢!
报错的是这行,mysql_fetch_row需要的是资源,但是传入确实bool值,查mysql_query的文档可以发现,查询出错的时候才会返回bool值false,所以你那个$name很有问题
有人帮忙看看吗~