I am trying to add pagination to my MySQL results page. My goal at the moment is is to divide the number of results in the column ($items_number
) by 10 since I want 10 results per page ($per_page = 10
).
I had to convert $items
into an array since it could not be read as a string, so now I have $items_number = mysqli_fetch_row($items)
;
When I echo this in my code to see the number of items in a column, I get a message that says:
Notice: Array to string conversion in /home/ikb2014/public_html/test/classic_cars/pag_test.php on line 46
But it also STILL returns a value that says 'Array'. How can I get the value to report the number of items in the column instead of the word 'Array'?
Code:
<?php
require_once("./includes/database_connection.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
$per_page = 10;
$query = "SELECT productCode, productName, productLine, productScale, productVendor, productDescription, buyPrice FROM products WHERE `productLine` = 'Classic Cars'";
$result = mysqli_query($dbc, $query)
or die(mysqli_error($dbc));
$query_count = "SELECT count(productLine) FROM products WHERE `productLine` = 'Classic Cars'";
$items = mysqli_query($dbc, $query_count)
or die(mysqli_error($dbc));
$items_number = mysqli_fetch_row($items);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Home</title>
<link type="text/css" rel="stylesheet" href="classic_cars.css" />
</head>
<body>
<?php
require_once("./includes/navigation.php");
?>
<?php
while ($row = mysqli_fetch_array($result)) {
$product_code = $row['productCode'];
$product_name = $row['productName'];
$product_line = $row['productLine'];
$product_vendor = $row['productVendor'];
$product_description = $row['productDescription'];
$buy_price = $row['buyPrice'];
echo "<tr>
<td><p>$product_name</p></td>
<td><p>$items_number</p></td>
</tr>";
} // end while ($row = mysqli_fetch_array($result))
?>
<?php
require_once("./includes/footer.php");
?>
</body>
</html>