Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search multiple mysql tables

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
GB
Hi all,

Im making a simple search script for my site.
I was going to try and incorporate the following simple code:

Code:
$query = "select * FROM table WHERE something like '%$keyword%' or something like '%$keyword%'"; 
$result = mysql_query($query) or die(mysql_error());

However i want to search multiple columns in 3 tables that i specify within the script. Im not to sure howto do this? All i want is 1 text box with the search button next to it, this box will pass the criteria to the query which will search the database. I can do this simple enough enough, but im not sure howto make the query search multiple tables and multiple columns within these tables with the keyword or words the user has entered.

All i need is abit of help with the forming the query. Writing the output code is easy.

Thanks alot

Jim
 
Code:
select a.thiscol, b.thatcol, c.thiscol from table a, table2 b, table3 c, table4 d where a.thiscol like '%this%' or b.thatcol like '%that%'

That way you can build big query. There are other ways to achieve what you are doing. Like keeping keywords in a separate table with a reference to the table and the row in that table and search that table rather than doing a search on multiple tables.

I am not very good with database stuff, so you might just wait for some more ppl to reply.... but this is how I would-a done.

You are either the slave of what made men or what men made.
 
ah rite yeh, i sort of see where your coming from with this. Anyone else got anything to add?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top