Jump to content

Recommended Posts

So I have a merchant table with merchant details. I want to be able to search for merchants by category. I have a category table that ties merchant IDs to category IDs so that merchants can have more than one category. But the problem I have is how do I make it search by a category if the category is in another table.

 

[search Box] [Drop down list of categories] [go]

 

Results page should display merchant details pulled from the merchant table based on the query but only on in a specific category.

 

In the category table there is merchantId and categoryId. And specific merchants might have more than one entry in that database if it falls into another category. I have everything else working except this search by category.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/89113-solved-mysql-search-by-category/
Share on other sites

Great thanks for the fast reply!

 

I have one more question and it is about the way I store category data. Is it more efficient to store categories in the merchants table by comma delimiting the category ids (for example under the category column: 12,25,1,7) or by doing it the way I am right now with a separate table that matches category ID to merchant ID?

 

Thanks.

Great thanks for the fast reply!

 

I have one more question and it is about the way I store category data. Is it more efficient to store categories in the merchants table by comma delimiting the category ids (for example under the category column: 12,25,1,7) or by doing it the way I am right now with a separate table that matches category ID to merchant ID?

 

Thanks.

 

As you have it now, normalised. Don't even consider 12,25,1,7

That is called aliasing. It basically just shortens the table name for the query so you don't have to type it out all the time.

 

That's part of the story. Sometimes it's essential if you meed to reference the same table twice in a query

 

eg

http://www.phpfreaks.com/forums/index.php/topic,180282.msg804214.html#msg804214

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.