I am pretty new to php and I am developing a website with a search bar.
I have used some code to implement a search query to search for products from my database. The search query works fines and displays all the required products which need to be displayed.
However, I want the items to have a link to the product details page which shows more information about that specific product. However, I do not have a clue how you would represent this as a link using html.
My search code is as follows:
[php]
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); $search_output = ""; if(isset($_POST['searchquery']) && $_POST['searchquery'] != ""){ $searchquery = preg_replace('#[^a-z 0-9?]#i', '', $_POST['searchquery']); if($_POST['filter1'] == "Food"){ $sqlCommand = "SELECT * FROM tbl_product WHERE pd_name LIKE '%$searchquery%'"; } include_once("config.php"); //Database connections below mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error()); mysql_select_db($dbName) or die(mysql_error()); $query = mysql_query($sqlCommand) or die(mysql_error()); $count = mysql_num_rows($query); if($count >= 1){ $search_output .= "$count results for $searchquery
"; while($row = mysql_fetch_array($query)) { $pd_name = $row["pd_name"]; $search_output .= "$pd_name
"; } // close while } else { $search_output = "
0 results for $searchquery
"; } } ?> Search for dishes : In: Food
The link I want it to reference to is:
[php]<a href="" . $_SERVER[‘PHP_SELF’] . “?c=$catId&p=$pd_id” . “”>$pd_name
[/php]
However, when adding this reference, it does not seem to work. Any help would be appreciated. Thanks in advance.