这代码是在网页中打印xsphpdb数据库中的表格phone,只是多了个分页功能,没1页显示10条记录,但提示错误为:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\xsphp\75jie\code\ido\fenye.php on line 12Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\xsphp\75jie\code\ido\fenye.php on line 16
phone Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\xsphp\75jie\code\ido\fenye.php on line 35
希望大神解答<?php
//step 1
$link=mysql_connect("localhost", "root", "123456") or die("connect error!");
//step 2
mysql_select_db("xsphpdb") or die("select db error!");function table($tablename){
$sql="select * from $tablename";
$num=10;
$result=mysql_query($sql);
$total=mysql_num_rows($result);
$sql="select * from {$tablename} limit {$offset}, {$num}";
$result=mysql_query($sql);
$cols=mysql_num_fields($result);
$url='fenye.php';
$cpage=isset($_GET['page'])?$_GET['page']:1;
$pagenum=ceil($total/$num);
$offset=($cpage-1)*$num+1;
$start=$offset+1;
$end=($cpage==$pagenum)? $total : ($cpage*$num);
$next=($cpage==$pagenum)? 0 : ($cpage+1);
$prev=($cpage==1) ? 0 : ($cpage - 1); echo '<table align="center" width="800" border="1">';
echo '<caption><h1>'.$tablename.'</h1></caption>';
echo '<tr>';
for($i=0;$i<$cols;$i++){
echo '<td><h4>'.mysql_field_name($result,$i).'</h4></td>';
}
echo '</tr>';
while($row=mysql_fetch_assoc($result)){
echo '<tr>';
foreach($row as $col){
echo '<td>'.$col.'</td>';
}
echo '</tr>';
}
echo '<tr><td colspan="'.$cols.'" align="right">';
echo '共有'.$total.'条记录,本页显示'.$start-$end.'条'.$cpage.'/'.$pagenum;
if($cpage==1){
echo " 首页 ";
}else{
echo " <a href='{$url}?page=1'>首页</a> ";
} if($prev)
echo " <a href='{$url}?page={$prev}'>上一页</a> ";
else
echo " 上一页 "; if($next)
echo " <a href='{$url}?page={$next}'>下一页</a> ";
else
echo " 下一页 ";
if($cpage==$pagenum)
echo " 尾页 ";
else
echo " <a href='{$url}?page={$pagenum}'>尾页</a> ";
echo '</td></tr>';
echo '</table>';
}mysql_close();table('phone');
phone Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\xsphp\75jie\code\ido\fenye.php on line 35
希望大神解答<?php
//step 1
$link=mysql_connect("localhost", "root", "123456") or die("connect error!");
//step 2
mysql_select_db("xsphpdb") or die("select db error!");function table($tablename){
$sql="select * from $tablename";
$num=10;
$result=mysql_query($sql);
$total=mysql_num_rows($result);
$sql="select * from {$tablename} limit {$offset}, {$num}";
$result=mysql_query($sql);
$cols=mysql_num_fields($result);
$url='fenye.php';
$cpage=isset($_GET['page'])?$_GET['page']:1;
$pagenum=ceil($total/$num);
$offset=($cpage-1)*$num+1;
$start=$offset+1;
$end=($cpage==$pagenum)? $total : ($cpage*$num);
$next=($cpage==$pagenum)? 0 : ($cpage+1);
$prev=($cpage==1) ? 0 : ($cpage - 1); echo '<table align="center" width="800" border="1">';
echo '<caption><h1>'.$tablename.'</h1></caption>';
echo '<tr>';
for($i=0;$i<$cols;$i++){
echo '<td><h4>'.mysql_field_name($result,$i).'</h4></td>';
}
echo '</tr>';
while($row=mysql_fetch_assoc($result)){
echo '<tr>';
foreach($row as $col){
echo '<td>'.$col.'</td>';
}
echo '</tr>';
}
echo '<tr><td colspan="'.$cols.'" align="right">';
echo '共有'.$total.'条记录,本页显示'.$start-$end.'条'.$cpage.'/'.$pagenum;
if($cpage==1){
echo " 首页 ";
}else{
echo " <a href='{$url}?page=1'>首页</a> ";
} if($prev)
echo " <a href='{$url}?page={$prev}'>上一页</a> ";
else
echo " 上一页 "; if($next)
echo " <a href='{$url}?page={$next}'>下一页</a> ";
else
echo " 下一页 ";
if($cpage==$pagenum)
echo " 尾页 ";
else
echo " <a href='{$url}?page={$pagenum}'>尾页</a> ";
echo '</td></tr>';
echo '</table>';
}mysql_close();table('phone');
$sql="select * from $tablename";
$num=10;
$result=mysql_query($sql);
$total=mysql_num_rows($result);
$sql="select * from {$tablename} limit {$offset}, {$num}";$offset 在哪里赋值的?
最好sql语句写在变量赋值 之后 不然没有值
把下边的代码修改为:
<?php
//step 1
$link=mysql_connect("localhost", "root", "123456") or die("connect error!");
//step 2
mysql_select_db("xsphpdb") or die("select db error!");function table($tablename){
$sql="select * from $tablename";
$num=10;
Echo $sql;
$result=mysql_query($sql);
$total=mysql_num_rows($result);
.....