Search more than 1 table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Radagast
Forum Newbie
Posts: 4
Joined: Wed Mar 18, 2009 4:50 am

Search more than 1 table

Post by Radagast »

Hi, Im a bit new to PHP so bare with

I want to make my existing search code search more than 1 table, I have this:

Code: Select all

$query = "select * from herbs where herbName like \"%$trimmed%\" OR herbLatinName like \"%$trimmed%\"   
  order by herbName";
how could I make it search a table called 'ailments' with fields called 'ailmentName', 'explanation' I've tried:

Code: Select all

$query = "select * from herbs where herbName like \"%$trimmed%\" OR herbLatinName like \"%$trimmed%\"   
  order by herbName and select * from ailments where ailmentName like \"%$trimmed%\"  OR explanation  like  \"%$trimmed%\"   
  order by ailmentName  ";
and i've tried a comma (,) Im not sure how to do this, can anyone help
thanx
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Search more than 1 table

Post by tech603 »

You have to do table joins. This link should help walk you through table joins.

Php mysql join Tutorial.
http://www.tizag.com/mysqlTutorial/mysqljoins.php

MySql docs on Table Joins
http://dev.mysql.com/doc/refman/5.1/en/join.html


Hope that helps.
Post Reply