tgmd Posted March 8, 2007 Share Posted March 8, 2007 I have a database that contains the columns keywords, month, day, year I need to search the keyword column, but here's the part I can't figure out, I need to search it within a date range. So I can search from 12/2/06 - 11/4/07 etc. I think I got most of it done, but I'm stuck on one issue. How do I get mysql/php to search a range? What I got so far: A script that can get the difference between the dates correctly (in my example it comes out as, 11, 2, 1) A basic search, where I can search by keywords and certain dates, but I cannot search by keywords in a range of dates. Any help would be greatly appreciated guys. Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/ Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 Im not sure why would you want to create 3 columns for day, month and year when you have so many formats available including timestamp, date and you can also save unix_timestamp in integer format.. You can easily query the database for date using all these 3 formats. Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202733 Share on other sites More sharing options...
Livijn Posted March 8, 2007 Share Posted March 8, 2007 You can put month-day-year together in one column. It's easier to handle. Name it `date` and set it to date. You can get in data with "date(Y-m-d);" Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202735 Share on other sites More sharing options...
tgmd Posted March 8, 2007 Author Share Posted March 8, 2007 Nah I can't this is part of a bigger project. The days month and year must be separate (I don't want to write a regular expression to separate them) But perhaps I could just put a time stamp in, in addition to the day, month, year. That would make more sense. How do I search within a range though? Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202738 Share on other sites More sharing options...
Livijn Posted March 8, 2007 Share Posted March 8, 2007 Nah I can't this is part of a bigger project. The days month and year must be separate (I don't want to write a regular expression to separate them) But perhaps I could just put a time stamp in, in addition to the day, month, year. That would make more sense. How do I search within a range though? You can seperate them by: list($year, $month, $day) = explode('-', $row['date']); Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202743 Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 If there is a date column in your table then $query = "select * from table where date between '$startdate' AND '$enddate'"; Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202748 Share on other sites More sharing options...
tgmd Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks! That did it for me... I barely use Mysql... Thanks again. Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202751 Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 Just store the date as a single DATE type field. If you need the separate elements you can SELECT MONTH(datecol) as m, DAY(datecol) as d, YEAR(datecol) as y FROM mytable" Link to comment https://forums.phpfreaks.com/topic/41803-how-to-get-phpmysql-to-search-within-a-range/#findComment-202860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.