Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/63058-php-filter-mysql-results/
Share on other sites

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.

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

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.