Jump to content

Recommended Posts

I've been trying many combinations of things, but I think what I need is some kind of join statement. I have two tables, xyz_dest and xyz_destloc. I'm performing a query that needs to find all of the rows in xyz_destloc that have a specific zipcode column but also checks to see if the 'title' column of xyz_dest is similar to the search term.

 

The method I'm trying to accomplish is to perform that search, but then only display DISTINCT rows from xyz_dest that show all of the rows from xyz_destloc that are relevant.

For example

 

xyz_destloc:

id  |  zipcode  |  address  |  destid(id from table xyz_dest)

1   |  12345    | 123 way  |  1

2   |  12345    | 412 street|  1

3   |  12344    | 123 xyz   |  1

4   |  54321    | 415 abc   |  2

 

xyz_dest:

id  |  title

1   | 'Destination 1'

2   | 'Destination 2'

3   | 'Destination 3'

 

 

So if I search for a title similar to 'destination' in the zipcode 12345, I would like it to return:

 

"Destination 1: 123 way & 412 street"

 

 

 

I hope that makes sense

Right now, my query is something like this - that does not function...

"SELECT xyz_dest.id, xyz_dest.title FROM xyz_dest, xyz_destloc ON xyz_destloc.destid=xyz_dest.id WHERE xyz_destloc.zipcode='$zipcode' AND xyz_dest.title LIKE '%$keywords%'"

 

Thanks a bunch!!!!

Link to comment
https://forums.phpfreaks.com/topic/93955-searching-two-tables-but-sorting-by-one/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.