Ad

PHP Script To Make A Link Out Of A MYSQL Result?

- 1 answer

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);
?>
Ad

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.

Ad
source: stackoverflow.com
Ad