Reputation: 1
I am getting search lists but i cannot click it to go to the respective pages of the items. What I should do ? I need to add hyperlinks to those options. Here is my code.
<?php
$key=$_GET['key'];
$array = array();
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("medical",$con);
$query=mysql_query("select * from medicine where med_name LIKE '%{$key}%'");
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['med_name'];
}
echo json_encode($array);
?>
Upvotes: 0
Views: 46
Reputation: 42384
You have a number of ways about going about this, but the easiest solution is to add the hyperlinks to the array. You can store the pages as links in the database, but I'm going to assume the pages are all called [med_name]
.html. To link to those, you would have to craft the hyperlink around the name itself:
$array[] += "<a href='" . $row['med_name'] . ".html'>" . $row['med_name'] . "</a>";
This will give you an array with indexes like:
<a href='field1.html'>field1</a>
<a href='field2.html'>field2</a>
Please keep in mind that MySQL has long since been deprecated. It's deprecated in PHP 5.5, and outright removed in PHP 7. I'd really recommend switching over to MySQLi or PDO instead :)
Hope this helps! :)
Upvotes: 1