Jump to content

Merging 3 Queries...


jwwceo

Recommended Posts

I have a master search box on my site that I want to do a bunch of things when submitted. Basically, I want customers to be able to enter anything in there..like keywords and colors and have the query look in a bunch of different places for matches.  I already have these 2 queries running, that search for kewywords and colors, but I'd like them to both be run when a customer inputs the search box. I'd also like it to query the item name and the notes field. The third query is displayed below but I'm not sure of the syntax on it...

At any rate... how can these three be combined to one varible that I can run in a while loop to display products on my page...I also only need one entry per item (shirt_id)...in case numerous fields match the search string...

mysql_query("SELECT * FROM shirtcolors
  LEFT JOIN colors ON shirtcolors.color_id = colors.color_id
  LEFT JOIN shirts ON shirtcolors.shirt_id = shirts.shirt_id
  WHERE color = '$colorsearch' ORDER BY shirts.$field $direction") or die(mysql_error());

mysql_query("SELECT * FROM shirtkeywords
    LEFT JOIN keywords ON shirtkeywords.keyword_id = keywords.keyword_id
    LEFT JOIN shirts ON shirtkeywords.shirt_id = shirts.shirt_id
  WHERE keyword = '$keywordsearch'  ORDER BY $field $direction") or die(mysql_error());

mysql_query("SELECT * FROM shirts WHERE notes like'%$search%' OR name like'%$search%'") or die(mysql_error());
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.