PHP Script To Make A Link Out Of A MYSQL Result?
So I made a test script for PHP output of a basic Mysql database. The problem is that I would like to make the auto increment called orderid to be able to become a link that I can click to open up a page that shows more info about that specific ID of that order.
It really seemed hard to find anything online and I have seen databases that have done this.
Also (not in this script) I have used CURRENT_TIMESTAMP but it doesn't put the current time, but does use the current date. What is the best way to get the current time (AM PM or 24 hour then convert it later) for MYSQL or PHP and input it?
Thank you for your help.
<?php
$con = mysqli_connect('localhost','user','password','database');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
else{
$sql="SELECT * FROM custinfo WHERE orderopen = 1";
$result = mysqli_query($con,$sql);
echo "<table border='1' bordercolor='blue' bgcolor='CCFFFF' cellpadding='0'>
<tr><h2> Open Orders:</h2>
<th>OrderID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Phone</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td><h3><font color='blue'>" . $row['orderid'] . "</font></h3></td>";
echo "<td><h3><font color='blue'>" . $row['firstname1st'] . "</font></h3></td>";
echo "<td><h3><font color='blue'>" . $row['lastname1st'] . "</font></h3></font></td>";
echo "<td><h3><font color='red'>" . $row['phone'] . "</font></h3></td>";
echo "</tr>";
}
echo "</table>";
}
mysqli_close($con);
?>
Answer
Well, if you just want to add an a
element to this line:
echo "<td><h3><font color='blue'>" . $row['orderid'] . "</font></h3></td>";
Then just add an a
element to it:
echo "<td><h3><font color='blue'><a href='somePage.php?id=" . $row['orderid'] . "'>" . $row['orderid'] . "</a></font></h3></td>";
Being a link doesn't make it particularly special, it's still just HTML like any other HTML that you're already outputting.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?