问答详情
源自:3-3 获取分页数据

老师,我想问一下

$sql = "select * from imooc_admin limit ".($page-1) * 2 .",2 ";
//把SQL语句传送数据中
$result = mysql_query($sql);
//处理数据
while ($row = mysql_fetch_assoc($result)){
    echo $row['id']. '-'. $row['username']. '-'. $row['email']. "<br>";
}

报错误:Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\APMServ5.2.6\www\htdocs\shopImooc\admin\test.php on line 24


但是改成$sql = "select * from imooc_admin " 可以显示表中所有内容,为什么呢?


提问者:慕田峪5074020 2015-07-02 09:49

个回答

  • 外星人_0005
    2015-08-12 22:44:24
    已采纳

    $sql = "select * from imooc_admin limit ".($page-1) * 2 .",2 ";改成下面两行就正确了

    $sql = "select * from imooc_admin limit ".($page-1) * 2;

    $sql.= ",2 ";

  • qq_ny_1
    2018-06-19 16:02:56

    非常感谢