Daleeburg Posted August 2, 2007 Share Posted August 2, 2007 I am making a calender and part of it is that i would like it to pull activities happening for that day out of a MySQL database, the problem is that i only know how do do this with anywhere from 28-31 MySQL calls (one call for each day), which is extremely slow. Is there a way that i can call the whole months activities in one call then use the results from the big call and filter it out by date. my database is set up like this Auto_int | Year | Month | Date | Activity_name ~D Quote Link to comment https://forums.phpfreaks.com/topic/63058-php-filter-mysql-results/ Share on other sites More sharing options...
squiggerz Posted August 2, 2007 Share Posted August 2, 2007 Have you tried using a query like mysql_query("SELECT Activity_name FROM db_table_name WHERE month = $thismonth"); and have $thismonth = date('m'); or $thismonth = date('F'); http://www.php.net/manual/en/function.date.php for reference. Hope I understood what you meant and that helps some. Quote Link to comment https://forums.phpfreaks.com/topic/63058-php-filter-mysql-results/#findComment-314142 Share on other sites More sharing options...
Daleeburg Posted August 2, 2007 Author Share Posted August 2, 2007 here is the basic code of what i am trying to fill. <?php require("functions/mfunc/navlinks.php"); If(isset($_GET['sec'])){ list($month, $year) = explode("_", $_GET['sec']); }ELSE{ $month = date(n); $year = date(Y); }; $monthname = date("F", mktime(0, 0, 0, $month, 1, $year )); IF($month == 1){ $lastmonth = 12; $year1 = $year - 1; }ELSE{ $lastmonth = $month - 1; $year1 = $year; }; $lastmonthname = date("F", mktime(0, 0, 0, $lastmonth, 1, $year )); IF($month == 12){ $nextmonth = 1; $year2 = $year + 1; }ELSE{ $nextmonth = $month + 1; $year2 = $year; }; $nextmonthname = date("F", mktime(0, 0, 0, $nextmonth, 1, $year )); echo '<center><table>'."\n ".'<tr>'; echo "\n ".'<td valign="bottom"><a href="/mcalender/'.$lastmonth.'_'.$year1.'">'.$lastmonthname.'</a></td>'; echo "\n ".'<td valign="top"><div id="calmon"><h2>'.$monthname." ".$year.'</h2></div></td>'; echo "\n ".'<td valign="bottom"><a href="/mcalender/'.$nextmonth.'_'.$year2.'">'.$nextmonthname.'</a></td>'; echo "\n ".'<tr>'."\n".'</table></center>'; $today = date(j); ?> <table id="calender"> <tr> <td class="calheader">Sunday</td> <td class="calheader">Monday</td> <td class="calheader">Tuesday</td> <td class="calheader">Wednesday</td> <td class="calheader">Thursday</td> <td class="calheader">Friday</td> <td class="calheader">Saturday</td> </tr> <tr> <?php $start = date("N", mktime(0, 0, 0, $month, 1, $year )); $lastday = date("t", mktime(0, 0, 0, $nextmonth, 0, $year)); $week = 0; $date = 1; while($start > 0){ IF($start == 7){ $start = 0; }Else{ echo"\n ".'<td class="calday"> </td>'; $week++; $start--; }; }; while($date <= $lastday){ IF($week == 7){ echo"\n ".'</tr><tr>'; $week = 0; }; IF($date == $today AND $month == date(n)){ $style = "caltoday"; }ELSE{ $style = "calday"; }; echo"\n ".'<td class="'.$style.'" valign="top"><div class="date">'.$date.'</div></td>'; $date++; $week++; }; while($week < 7){ echo"\n ".'<td class="calday"> </td>'; $week++; } ?> </tr> </table> That makes a full calender for whatever month it is and allows you to go back or forward in time as much as you want (it is currently set up for a server with httacces rules so you may not be able to go back and forward) I am trying to get it to the point where it will put whatever activities that the people want in it. The problem is that I only know how to put the activites by adding a call like mysql_query("SELECT* FROM db_table_name WHERE year = $year AND month = $month AND date = $date"); At every single day in the calender, which would not be the end of the world, but it would be EXTREMELY taxing on the database, and slow everything down. It would be nice if i could do a query like mysql_query("SELECT* FROM db_table_name WHERE year = $year AND month = $month"); (notice the lack of a Where date) and then use the php to sort out the results by date. That is where the other problem comes in, I dont know how or if PHP can do this. thanks ~D Quote Link to comment https://forums.phpfreaks.com/topic/63058-php-filter-mysql-results/#findComment-314150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.