doudengjin8251 2014-05-01 17:36
浏览 39

未定义的偏移:0错误

I'm having this error on my code

Notice: Undefined offset: 0 in C:\xampp\htdocsekmovie\paginator.php on line 29

here is the full code

<?php 
$con=mysql_connect("localhost","root","");
$conn=mysql_select_db('rektechnologies'); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  } // include your code to connect to DB.
if (!empty($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * 20; 
$sql = "select * from videos order by id desc LIMIT $start_from, 10";
$rs_result = mysql_query($sql,$con); 
?> 
<table>
<tr><td>Name</td><td>Phone</td></tr>
<?php 
while ($row = mysql_fetch_assoc($rs_result)) { 
?> 
            <tr>
            <td><? echo $row["path"]; ?></td>
            <td><? echo $row["description"]; ?></td>
            </tr>
<?php 
}; 
?>
<?php 
$sql = "SELECT COUNT(*) FROM videos"; 
$rs_result = mysql_query($sql,$con); 
$row = mysql_fetch_assoc($rs_result); 
$total_records = $row[0];
$total_pages = ceil($total_records / 10);
for ($i=1; $i<=$total_pages; $i++) { 
    echo "<a href='paginator.php?page=".$i."'>".$i."</a> "; 
}; 
?>
</table>

can anyone help me with the error

  • 写回答

3条回答 默认 最新

  • dongyue8640 2014-05-01 17:38
    关注

    You are using mysql_fetch_assoc, but then trying to access the column name by integer

    $row = mysql_fetch_assoc($rs_result);
    $total_records = $row[0];
    

    use either

    $row = mysql_fetch_assoc($rs_result);
    $total_records = $row['COUNT(*)'];
    

    or

    $row = mysql_fetch_array($rs_result);
    $total_records = $row[0];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致