I have a page which displays a table of product details, based on a link that the user selected on another page. The code is:
<h2>Order detail</h2>
Order: <?php echo $_GET["order_no"]; ?><br />
<?php
// -- Connect to the MySQL server
$con = mysql_connect ('xxxxx', 'xxxxxx', 'xxxxx' );
// -- End process if 'mysql_connect' does not return a TRUE value
if (!$con )
{
die('Could not connect to the database: ' . mysql_error());
}
// -- Otherwise continue process and 'echo' information
echo "<p>Database is connected</p>";
// -- Use SQL to create a table:
mysql_select_db("xxxxxx", $con);
// -- Execute the statement in $sqlStatement with mysql_query();
mysql_query($sqlStatement,$con);
$result = mysql_query("SELECT order_no, panel_product_no, product_quantity
FROM orderConsistsOfPanel
WHERE order_no = " . $_GET["order_no"]);
echo "<table border='5'>
<tr>
<th>order_no</th>
<th>panel_product_no</th>
<th>product_quantity</th>
</tr>";
// -- Use 'while' to check each row in $result in turn:
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['order_no'] . "</td>";
echo "<td>" . $row['panel_product_no'] . "</td>";
echo "<td>" . $row['product_quantity'] . "</td>";
echo "</tr>";
}
echo "</table>";
//close the connection
mysql_close($con);
?>
</body>
</html>
Thanks to the advice from another question I asked the $_GET is working to filter the results. I also echoed the $_GET value in the headings. But I am stuck on the next bit...
I want to do several things. The first is to use the $_GET in a mysql statement to display some extra html text below the headings. Something like:
Customer: <?php echo mysql_query(SELECT name
FROM orders
WHERE order_no = " . $_GET["order_no"]); ?>
But I have no idea how to do this or where to put it in the page. I'm assuming it needs to go after the DB connection bit otherwise it won't connect. I'm guessing I need to use $result and/or $row but I don't know how or where...
The second thing is connected to this in the sense that I don't know how to organise multiple bits of PHP/mysql/HTML on the same page. Basically I need another table on the page below the one I have, which is very similar to the one above (but takes results from a different table) and again uses the same $_GET.
Can anyone help?
mysql_*
functions to write new code. They are no longer maintained and the community has begun deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide which, this article will help you. If you pick PDO, here is good tutorial. – Truth 4 mins agomysql_*
even if this is temporary solution – riwette 4 mins agomysqli
orPDO
. It's worth learning now so you don't have to rewrite your code later. – Matt 36 secs ago