dovgqc2648 2015-06-18 11:37
浏览 54

从mysqli获取数据的致命错误

Set pagination, on $result1 are fetching all rows from table and, $new_result set its LIMIT. But i got an error "Fatal error: Call to a member function fetch_assoc() on a non-object in /home/...."

$page_limit = 28;
$table_name_3 = 'table';

if (!isset($_GET['page']) )
    { $start=0; } else
    { $start = ($_GET['page'] - 1) * $page_limit; }

$mysqli = new mysqli("xxxxxxx" , "xxxxxxx" , "xxxxxxx" , "xxxxxxxxx");
$result1 = $mysqli->query( "SELECT * FROM $table_name_3 
                 WHERE `categories` LIKE  '$newq'
                 AND   `inStock` LIKE 'true' ");
while ( $rows =  $result1->fetch_assoc() ) {

$new_result = $mysqli->query( $rows . "LIMIT $start,$page_limit " );
while ( $rows =  $new_result->fetch_assoc() ) {

$total = mysqli_num_rows($result);
$store = $rows['store'];
$productId = $rows['productId'];
  • 写回答

2条回答 默认 最新

  • doutangguali32556 2015-06-18 11:46
    关注

    This is not the right way to do it, as your $rows object contains an array of fetched results -> $row['columnname'], $row['columnname2'] and so on. Instead, use it in one query :

    "SELECT * FROM $table_name_3 WHERE `categories` LIKE  '$newq' 
                                AND `inStock` LIKE 'true' 
                                LIMIT ($page_limit-$offset) OFFSET $offset"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看