Jump to content

Help with a php even calendar


Abaddon1979

Recommended Posts

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.

[code]<?
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++;

}

?> [/code]
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.


[code]<?
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++;

}

?> [/code]
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?
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=107945.msg433827#msg433827 date=1158187206]
Do you have an example of it anywhere that I can check it out?

Rich
[/quote]
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.
Link to comment
Share on other sites

checkcal.php

[code]<?

$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';
}
?> [/code]


Raidcal.php

[code]
<?

$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"; }

?>[/code]




Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.