Reputation: 1
I am trying to make the results from mysql results clickable links in php. I am new to php and please help.
<?php mysql_connect("localhost", "root", "pass") or die(mysql_error());
mysql_select_db("Branches") or die(mysql_error());
$data = mysql_query("SELECT * FROM items order by ID desc Limit 5") or die(mysql_error());
while ($info = mysql_fetch_array($data)) {
echo $info['title'];
echo " <br>";
echo $info['descr'];
echo "<br>";
echo "<br>";
} ?>
Upvotes: 0
Views: 7611
Reputation: 9823
while ($info = mysql_fetch_array($data)) {
echo '<a href="somefile.php?id='.$info['ID'].'">'.$info['title'].'</a>';
echo " <br>";
echo $info['descr'];
echo "<br>";
echo "<br>";
}
Then in somefile.php
, use $_GET
to capture the id and show the results
$id = $_GET['id'];
// pull info from db based on $id
$sql = mysql_query('SELECT * FROM items WHERE ID = "'.$id.'"');
.
.
.
.
Upvotes: 1
Reputation: 942
echo '<a href="php page which you want to display on click">$info['descr']</a>'
Upvotes: 0
Reputation: 30488
just use anchor tag like this
while ($info = mysql_fetch_array($data)) {
echo "<a href =\"$info[title]\">".$info['title'];. "</a>";
}
Upvotes: 0