I have the following code:
$productQuery = "SELECT ean, name FROM products WHERE category = '$category'"; $productResult = $mysqli->query($productQuery); while ($productRow = $productResult->fetch_assoc()) { $productPriceQuery = "SELECT ean, price+shipmentCost AS totalPrice FROM prices WHERE ean = $productRow[ean] ORDER BY totalPrice ASC"; $productPriceResult = $mysqli->query($productPriceQuery); $totalPrice = $productPriceResult->fetch_assoc(); echo $productPriceResult["productURL"]; }
But I am getting the following error for the echo line:
PHP Fatal error: Cannot use object of type mysqli_result as array in file.php
I already read some articles on this website and other websites but did not understand the problem and could not solve it myself.
$productPriceResult
is a sql result, not a fetched array. Is "productURL" stored in theproducts
table? – showdev Dec 5 '13 at 23:32mysqli
you should be using parameterized queries andbind_param
to add user data to your query. Avoid using string interpolation to accomplish this. – tadman Dec 5 '13 at 23:39