jwwceo Posted September 6, 2006 Share Posted September 6, 2006 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 https://forums.phpfreaks.com/topic/19866-3-queries-at-oncehow-to-do-this/ Share on other sites More sharing options...
roopurt18 Posted September 6, 2006 Share Posted September 6, 2006 Store the results of each query in an array: $arr1, $arr2, $arr3, etc.Each array is basically a set, so we take the UNION of any two minus their INTERSECTION.$Result = array_merge( $arr1, array_diff($arr2, $arr1) );$Result = array_merge( $Result, array_diff($arr3, $Result) );Perhaps there is a better way, but that should do the trick. Link to comment https://forums.phpfreaks.com/topic/19866-3-queries-at-oncehow-to-do-this/#findComment-87281 Share on other sites More sharing options...
Daniel0 Posted September 6, 2006 Share Posted September 6, 2006 [code]mysql_query("query 1; query2; query 3;");[/code]If you don't understand what I mean, then I mean that you just have to seperate the queries with semi-colons ( [tt];[/tt] ). Link to comment https://forums.phpfreaks.com/topic/19866-3-queries-at-oncehow-to-do-this/#findComment-87284 Share on other sites More sharing options...
roopurt18 Posted September 6, 2006 Share Posted September 6, 2006 The mysql_query documentation says the query should not end with a semicolon. I've not tried submitting multiple queries in that way, but would that return all of the results in a single result set? Link to comment https://forums.phpfreaks.com/topic/19866-3-queries-at-oncehow-to-do-this/#findComment-87308 Share on other sites More sharing options...
zq29 Posted September 6, 2006 Share Posted September 6, 2006 Please do not double post. You have posted the same question in our MySQL forum, where it should be - So this one is locked and will be deleted shortly. Link to comment https://forums.phpfreaks.com/topic/19866-3-queries-at-oncehow-to-do-this/#findComment-87318 Share on other sites More sharing options...
Recommended Posts