Jump to content


Photo

Help with a php even calendar


  • Please log in to reply
7 replies to this topic

#1 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 September 2006 - 08:23 PM

I have recently started working on a php event calender and I'm a bit stuck on a particular function I want the calendar to have.


So here is the code I currently have. It searches the database and comes up with all the events for a particular day the $eventid is passed to the page from the address.

<?
include 'db.php';

$query="SELECT * from calendar where starttime LIKE '$eventid%' ORDER BY 
starttime";
$result=mysql_query($query);

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$submiter=mysql_result($result,$i,"submiter");
$instance=mysql_result($result,$i,"instance");
$event_finish=mysql_result($result,$i,"event_finish");
$raiddisc=mysql_result($result,$i,"raiddisc");
$repeat=mysql_result($result,$i,"repeat");

$i++;

}

?>

Now I'm still working on the repeatable events. The $repeat is a enum with the days of the week Saturday, Sunday, Monday ect. So what I was thinking is I could just add another mysql search and do the code much the same way it was done as above.


<?
include 'db.php';

$query="SELECT * from calendar where repeat LIKE '$dayofweek%' ORDER BY 
starttime";
$result=mysql_query($query);

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$submiter=mysql_result($result,$i,"submiter");
$instance=mysql_result($result,$i,"instance");
$event_finish=mysql_result($result,$i,"event_finish");
$raiddisc=mysql_result($result,$i,"raiddisc");
$repeat=mysql_result($result,$i,"repeat");

$i++;

}

?>

The problem is if I add a event for Wednesday september 13th (2006-09-13) and then check the event calendar for that day it will repeat the same output twice. Is there a way I can avoid this?

#2 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 September 2006 - 10:17 PM

*bump*

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 September 2006 - 10:40 PM

Do you have an example of it anywhere that I can check it out?

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 September 2006 - 11:22 PM

Do you have an example of it anywhere that I can check it out?

Rich

http://dev.steel-legion.com


The first posts code in action. It works but it Inst that great.

In the database there is three records. Two are for the 13th of September. One is for the 20th.

Here is the problem. The record from the 20th has an enum of Wednesday(which shows its repeatable). Which is fine every Wednesday it does show up, you can go to October and click on any Wednesday and you will see there is a record.

However if you click on the 20th you will see two records.

This is because it is searching for the event date 2006-09-20 as well as the repeat enum of Wednesday and it is showing up twice.

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 September 2006 - 11:35 PM

Can you show the full php code for checkcal.php?

That would really help.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 12:00 AM

checkcal.php

<?

$eventid = $_REQUEST['eventid'];
$calday = date('l', strtotime($_REQUEST['eventid']));
$calmonth = date('F', strtotime($_REQUEST['eventid']));
$calyear = date('Y', strtotime($_REQUEST['eventid']));
$caldate = date('jS', strtotime($_REQUEST['eventid']));

$sql = "SELECT * from calendar where starttime LIKE '$eventid%' ORDER BY starttime"; 
$result = mysql_query($sql) or die ("Invalid query");

if (!mysql_num_rows($result)) { 
$sql = "SELECT * from calendar where repeat LIKE '$calday%' ORDER BY starttime"; 
$result = mysql_query($sql) or die ("Invalid query"); 
}


if (!mysql_num_rows($result)) { echo "<body bgcolor=\"#222222\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"100%\" width=\"100%\"><tr><td valign=\"middle\" align=\"middle\"><font class=\"fontstyle\">I'm sorry, but there are no raids scheduled for $calday, $calmonth $caldate $calyear..</font></td></tr></table></body>";
} else { 
include 'raidcal.php';
} 
?>



Raidcal.php

<?

$query="SELECT * from calendar where starttime LIKE '$eventid%' ORDER BY 
starttime";
$result=mysql_query($query);

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$submiter=mysql_result($result,$i,"submiter");
$instance=mysql_result($result,$i,"instance");
$event_finish=mysql_result($result,$i,"event_finish");
$raiddisc=mysql_result($result,$i,"raiddisc");
$repeat=mysql_result($result,$i,"repeat");

$i++;

echo "Table junk"; }

$query="SELECT * from calendar where repeat LIKE '$calday%' ORDER BY 
starttime";
$result=mysql_query($query);

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

$id1=mysql_result($result,$i,"id");
$submiter1=mysql_result($result,$i,"submiter");
$instance1=mysql_result($result,$i,"instance");
$event_finish1=mysql_result($result,$i,"event_finish");
$raiddisc1=mysql_result($result,$i,"raiddisc");
$repeat1=mysql_result($result,$i,"repeat");

$i++;


echo "Table junk"; }

?>






#7 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 01:34 AM

I thought about this on my drive home and came to a simple solution. I can just add another database and search that instead. That way when i search for the date it will only show the single events and when I search for the day it will show the recurring, then it will only display once.

If I do that is there I can use php to sort both while loop outputs instead of executing them one after another? And if I can where do i start?

#8 Abaddon1979

Abaddon1979
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 03:33 PM

*bump*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users