mikebyrne Posted April 4, 2008 Share Posted April 4, 2008 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."; } ?> Quote Link to comment Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted April 4, 2008 Author Share Posted April 4, 2008 So what would i have to do to dispaly the information in product.php? Quote Link to comment Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted April 4, 2008 Author Share Posted April 4, 2008 Thats geat, thanks for your help!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.