注意:数组转换为字符串

时间:2014-02-10 18:32:04

标签: php html

我正在进行分页,我得到此错误是我第一次使用此错误,感谢您的帮助,谢谢!

try {

    // Find out how many items are in the table
    $total = $con -> query('SELECT company_name, email, tel, website 
             FROM company') -> fetch_assoc();

    // How many items to list per page
        $limit = 10;
    // How many pages will there be
         $pages = mysqli_fetch_array($total, $limit);
    // What page are we currently on?
         $page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array (
             'option' => array(
                 'default' => 1,
                 'min_range' => 1,
             ),
         )));
    // Calculate the offset for the query
         $offset = ($page - 1) * $limit;
    // Some information to display to the user
         $start = $offset + 1;
         $end = min(($offset + $limit), $total);
    // The "back" link
         $prevlink = ($page > 1) ? '<a herf="?page=1" title = "First page"> &laquo;</a>
       <a href="?page=' . ($page - 1) . '" title="Previous page">&lsaquo;</a>' : '<span 
   class="disabled">&laquo;</span> <span class="disabled">&lsaquo;</span>';
    // The "forward" link
  $nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next
   page">&rsaquo;</a> <a href="?page=' . $pages . '" title="Last page">&raquo;</a>' : 
   '<span class="disabled">&rsaquo;</span> <span class="disabled">&raquo;</span>';  



  }

catch (Exception $e) 
{
    echo '<p>', $e->getMessage(), '</p>';
}

这是我收到错误的行。

注意:第212行的C:\ xampp \ htdocs \ pritcluster \ register_companies.php中的数组到字符串转换

       // Display the paging information
  echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' of ',
      $pages, ' pages, displaying ', $start, '-', $end, ' of ', $total,
      'results ', $nextlink, ' </p></div>';

1 个答案:

答案 0 :(得分:0)

您收到错误,因为$pages是一个数组。看起来您想要吐出该数组中的项目数,在这种情况下,您应该将$pages替换为count($pages)

echo '<div id="paging"><p>', $prevlink, ' Page ', $page, ' of ',
      count($pages), ' pages, displaying ', $start, '-', $end, ' of ', count($total),
      'results ', $nextlink, ' </p></div>';

同样适用于$total