Jump to content

[SOLVED] display results and link to product.php?id= ??????


mikebyrne

Recommended Posts

At present I have a searchfield that dispalys the result in searchresults.php. Is it possible to have the "ProductName" linked so that it would return the results in a page called product.php? Something like product.php?id= (id= being the ProductNo)

 

login

<form name="ex2" method="post" action="searchresults.php">

<select name="cat" onChange="setAction(this.options[this.selectedIndex].value);"> 
<option value="CD" selected="selected" >CDs</option>
<option value="DVD" >DVDs</option>
<option value="Game" >Games</option>
</select>



<input type="text" name="searchfield" size="22" maxlength="40" id="srchdrop" />
<input type="submit" name="searchme" value="Search Now! »" id="gosrch" />

</td></tr>
</form>
</table>

 

searchresults.php

<?PHP

if (isset($_POST['searchme'])) {

include("adminconnect.php");

$tbl_name = "product";

$cat = mysql_real_escape_string($_POST['cat']);
$input =mysql_real_escape_string($_POST['searchfield']);

$query = "SELECT * FROM product WHERE Producttype = '$cat' AND Productname LIKE '%$input%'";

$result = mysql_query($query) or die ("error in the query" . mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { echo "Title ".$row['ProductName']."\n<br> <img src=\"".$row['Image']."\"></img>\n<br>
Amount in stock ".$row['Stockamount']."\n<br> Price ".$row['Price']."\n<br>
Description: ".$row['Description']."\n<br>";
     }
} else {
    echo "No search results found";
}
} else {
    echo "No search terms entered.";
}

?>

 

 

Yes

<?php

if (isset($_POST['searchme'])) {

include("adminconnect.php");

$tbl_name = "product";

$cat = mysql_real_escape_string($_POST['cat']);
$input =mysql_real_escape_string($_POST['searchfield']);

$query = "SELECT * FROM product WHERE Producttype = '$cat' AND Productname LIKE '%$input%'";

$result = mysql_query($query) or die ("error in the query" . mysql_error());
  if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_array($result)) {
    echo "Title <a href=\"product.php?id=".$row['productid']."\">".$row['ProductName']."</a>\n<br> <img src=\"".$row['Image']."\"></img>\n<br>
    Amount in stock ".$row['Stockamount']."\n<br> Price ".$row['Price']."\n<br>
    Description: ".$row['Description']."\n<br>";
    }
  } else {
  echo "No search results found";
  }
} else {
    echo "No search terms entered.";
}

?>

 

I am assuming the product id is in a field called productid if not then change it to the field name.

Ray

you would just run a query based on the id

<?php
$id = $_GET['id'];
$sql = "SELECT * FROM product WHERE productid = '$id'";
$res = mysql_query($sql) or die(mysql_error());
// Since you are getting only one row no neew to loop
$row = mysql_fetch_assoc($res);
// now just echo all your fields below and format it the way you like

?>

 

Ray

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.