ipuck Posted August 13, 2009 Share Posted August 13, 2009 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 More sharing options...
TeNDoLLA Posted August 13, 2009 Share Posted August 13, 2009 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'; Link to comment https://forums.phpfreaks.com/topic/170014-php-database-search-help/#findComment-896910 Share on other sites More sharing options...
ipuck Posted August 13, 2009 Author Share Posted August 13, 2009 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. Link to comment https://forums.phpfreaks.com/topic/170014-php-database-search-help/#findComment-896916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.