Jump to content

PHP database search help


ipuck

Recommended Posts

I have a database of items as follow:

 

 

YearColorStyle

2000-2004BlueSoft

2000-2004RedSoft

2000-2004BlueHard

1996-1999BlueSoft

1996-1999RedSoft

1996-1999BlueHard

 

I have no problem looking for all the items of one color or style, but I do have problems looking for items for a certain year. For example if I want "2001"-"Red"-"Soft". How can I make the query to the database?

 

Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/170014-php-database-search-help/
Share on other sites

Something like this..

 

SELECT * FROM some_table WHERE Year = '2000-2004' AND Color = 'Red' AND Style = 'Soft';

 

or if yo want all the items between two year values.. I think you should have built your db a bit differently. Two columns start_year and end_year for example. Then you could do like this:

SELECT * FROM some_table WHERE Year BETWEEN '2001' AND '2003' AND Color = 'Red' AND Style = 'Soft';

Thank you very much for your answer, unfortunately I didn't built the database, I'm just trying to extract the information.

 

But you answer actually give the idea how to do it.

 

I can easily split the column and use the second code you provide. I didn't know about the BETWEEN code.

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.