For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2004 > Joining Tables for Search









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Joining Tables for Search
Harry G

2004-07-25, 8:56 pm

Hi,

I want to run a query on a table while joining it with other tables.

Table 1- members
id - firstname - middlename - ....- country - region3

Fields country and region3 hold the integer codes for country and region3 is state

Table 2- country
id - countryname
Countryname is where the actual Country name is stored and id is the country code

Similarly Table 3 - region3
id - region3 where region3 is the state name and id is the region code.

I perform the following query to search the names in the database but the result only gives me the integer values for Country and Region3. That's because, the code is only stored in the database. But I need to join the table 2&3 with 1 so I can extract names of country or region3 rather than integer values.

How would I modify the query below?

$keywords are the search words.

$query = "
SELECT id, firstname, familyname, middlename, fathername, region3, region4, country,
MATCH(firstname, middlename, familyname, fathername) AGAINST ('$keywords' IN BOOLEAN MODE) AS score
FROM members
WHERE MATCH(firstname, middlename, familyname, fathername) AGAINST ('$keywords' IN BOOLEAN MODE) ORDER BY score DESC";

Thanks
Harmeet


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com