gordo2dope Posted August 23, 2007 Share Posted August 23, 2007 ok, well i had this problem in the past when selecting from 2 tables to add to a shopping cart functions. But the solution does not seem to work in this situation. I'm trying to SELECT from 2 tables for a SEARCH feature. here is the sample of code im using for the query. I need to SELECT from table "mczippo1" and table "partsitems". I have tried doing a UNION, JOIN, JOIN LEFT. I also tried making 2 seperate queries and creating a third function that = the 2 queries. this sample below has just 1 table. This is the code that works. anything other than this gives me an error. Please take a crack at it and add whatever to also search from table "partsitems". [pre] $strSQL = mysql_query("SELECT * FROM `mczippo1` WHERE Detail LIKE '%$search%' OR Partnum LIKE '%$search%' OR THEME LIKE '%$search%' OR Cat1 LIKE '%$search%' OR Cat2 LIKE '%$search%' AND OnHand > MinQty GROUP BY Style ORDER BY OnHand Desc"); $anymatches=mysql_num_rows($strSQL); [/pre] Quote Link to comment Share on other sites More sharing options...
gordo2dope Posted August 23, 2007 Author Share Posted August 23, 2007 here is the union i tried... i also tried it as a join and join left, but nothing. also tried just the 1st section as 'mczippo1,'partsitems' and it didnt work either. [pre] $strSQL = mysql_query("SELECT * FROM `mczippo1` WHERE Detail LIKE '%$search%' OR Partnum LIKE '%$search%' OR THEME LIKE '%$search%' OR Cat1 LIKE '%$search%' OR Cat2 LIKE '%$search%' AND OnHand > MinQty GROUP BY Style ORDER BY OnHand Desc UNION SELECT * FROM `partsitems` WHERE Detail LIKE '%$search%' OR Partnum LIKE '%$search%' OR Cat1 LIKE '%$search%' OR Cat2 LIKE '%$search%' AND OnHand > MinQty ORDER BY OnHand Desc"); $anymatches=mysql_num_rows($strSQL); [/pre] Quote Link to comment Share on other sites More sharing options...
fenway Posted August 23, 2007 Share Posted August 23, 2007 Sounds like the tables have different fields... specifically get back the ones you want. Quote Link to comment Share on other sites More sharing options...
gordo2dope Posted August 23, 2007 Author Share Posted August 23, 2007 they have the same fields, some are different, but the ones i need to retrieve are the same. that was the problem I had with my other UNION for the shopping cart that I had. however this can't be the same case because they are the same exact fields that it needs to search for.... ? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 27, 2007 Share Posted August 27, 2007 they have the same fields, some are different, but the ones i need to retrieve are the same. that was the problem I had with my other UNION for the shopping cart that I had. however this can't be the same case because they are the same exact fields that it needs to search for.... ? If "some are different" then you need to specifically list the ones you want. 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.