我的代码出现了这个错误
注意:未定义的偏移量:第29行的C:\ xampp \ htdocs \ rekmovie \ paginator.php中的0
这是完整的代码
<?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>
任何人都可以帮我解决错误
答案 0 :(得分:2)
更改
$row = mysql_fetch_assoc($rs_result);
为:
$row = mysql_fetch_row($rs_result);
mysql_fetch_assoc
会返回一个关联数组,但您正在尝试访问需要索引数组的$row[0]
。
答案 1 :(得分:0)
您正在使用mysql_fetch_assoc,但之后尝试按整数
访问列名$row = mysql_fetch_assoc($rs_result);
$total_records = $row[0];
使用
$row = mysql_fetch_assoc($rs_result);
$total_records = $row['COUNT(*)'];
或
$row = mysql_fetch_array($rs_result);
$total_records = $row[0];
答案 2 :(得分:0)
将查询更改为SELECT COUNT(*) as some_alias FROM videos
然后使用$total_records = $row['some_alias'];