Php search with multiple fields result ques?

Reply

Join Date: Feb 2009
Posts: 6
Reputation: apollokid is an unknown quantity at this point 
Solved Threads: 0
apollokid apollokid is offline Offline
Newbie Poster

Php search with multiple fields result ques?

 
0
  #1
Feb 4th, 2009
Hi all, this is my first post and was wondering if someone can help me
See I have a search field with a results.php and I want to have results from multiple fields.
<form id="form1" name="form1" method="get" action="results.php">
    Search: 
    <label>
    <input type="text" name="findthis" id="findthis" />
    </label>
    <label>
    <input type="submit" name="button" id="button" value="Go" />
    </label>
  </form>

i can get only from one category with this code
results.php:
<?php
require_once("connect.php");
$mysearch = $_GET['findthis'];
$mystuff = mysql_query("SELECT product_id, product_name, furnishings_thumb, furnishings_info, lighting_info,lighting_thumb FROM Products_tbl WHERE product_name LIKE '%".$mysearch."%' ORDER BY product_name ASC");

while($row=mysql_fetch_array($mystuff)) {
print "<tr><td><img src='images/thumbs/".$row['furnishings_thumb']."' /></td><td>".$row['product_name']."</td><td>".$row['furnishings_thumb']."</td><td>".$row['furnishings_type']."</td><td><a href='furnishings_details.php?product_id=".$row['product_id']."'>more...</a></td></tr>";
}
?>

I want someone to search a product name and get results from either lighting or furnishing depending on what was searched, say couch or lamp.I am only allowed to get results with furnishings how would i be able to get results for the lightings and furnishings
thanks if anyone can help
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: marcosjp is an unknown quantity at this point 
Solved Threads: 0
marcosjp marcosjp is offline Offline
Light Poster

Re: Php search with multiple fields result ques?

 
0
  #2
Feb 6th, 2009
What you can do (as one of many possible solutions) is create two arrays each containing the product names valid for furnishing and lightings and then use a conditional structure to build the final SQL.

You can use the in_array function to check if a searched product name is present in each product name array.

This way you can have different queries according to the product being searched.
Last edited by marcosjp; Feb 6th, 2009 at 7:42 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 604 | Replies: 1
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC