2014-02-10 78 views
0

我正在使用分頁,我得到這個錯誤是我第一次使用這個工作,我非常感謝幫助,謝謝!注意:數組到字符串的轉換在

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>'; 
} 

這是我得到的錯誤。

說明:Array對C字符串轉換:\ XAMPP \ htdocs中\ pritcluster \ register_companies.php上線212

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

'$ pages'是一個數組。你不能像字符串一樣使用它。 –

+0

錯誤信息非常清晰,我認爲。 – woz

回答

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

+0

錯誤仍然在說相同的事情 – Mikasuki

+0

出於同樣的原因,嘗試在'$ total'周圍放置'count()'。 – woz

+0

我修好了!在變量$總需要把相同的東西計數($總)謝謝! – Mikasuki

相關問題