Hi All,
I know the code is poorly written, I am new and im trying to learn the basics first before I can understand what is actually bad and what i acceptable. I do appreciate all help though.
I am trying to run two sql queries in a PHP page but when i copy and past the ‘working’ code from the first part it errors on the second…
I recognise that result and row become a variable so tried to wipe those variables as it reaches the next instance of the code but still get an error on the second part. Surely I can run multiple queries, just why doesnt it like it?
I know in my past posts im told to turn on errors which i thought I had, but the result saying "error: " doesnt help me. So while I wait for help on here, i will be proactive and try and google errors and how to display errors further.
I am trying to learn.
TIA
Lee
<!-- #####################STEAKS######################### -->
<hr>
<h5><u>BUTCHERS CORNER:</u></h5>
<hr>
<?php
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM products WHERE catagory = 'Steaks' ORDER BY item"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table class='table table-striped'>";
// set table headers
echo "<tr>
<th></th><th>ITEM</th><th>COST</th><th>SIZE</th><th>CATAGORY</th><th>QTY</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
// echo "<td>" . $row->id . "</td>";
echo "<td></td>";
echo "<td>" . $row->item . "</td>";
echo "<td>£ " . $row->cost . "</td>";
echo "<td>" . $row->size . "</td>";
echo "<td>" . $row->catagory . "</td>";
echo "<td><input type='number' min='0' max='99' value='0' name='".$row->id."'></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
// $result='';
// $row='';
?>
</table>
<!-- ######################MORE MEAT######################## -->
<hr>
<h5><u>MORE MEAT:</u></h5>
<hr>
<?php
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM products WHERE catagory = 'Snacks' ORDER BY item"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table class='table table-striped'>";
// set table headers
echo "<tr>
<th></th><th>ITEM</th><th>COST</th><th>SIZE</th><th>CATAGORY</th><th>QTY</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
// echo "<td>" . $row->id . "</td>";
echo "<td></td>";
echo "<td>" . $row->item . "</td>";
echo "<td>£ " . $row->cost . "</td>";
echo "<td>" . $row->size . "</td>";
echo "<td>" . $row->catagory . "</td>";
echo "<td><input type='number' min='0' max='99' value='0' name='".$row->id."'></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
?>
</table>