943,733 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1075
  • PHP RSS
Feb 4th, 2009
0

Php search with multiple fields result ques?

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
apollokid is offline Offline
16 posts
since Feb 2009
Feb 6th, 2009
0

Re: Php search with multiple fields result ques?

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
marcosjp is offline Offline
42 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How can i check if http is present in img tag
Next Thread in PHP Forum Timeline: Passing ID from one page to another





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC