Jump to content

Recommended Posts

sql = "SELECT * FROM events WHERE date='$d-$m-$y'";
	echo $sql;
$postsresult = mysql_query($sql);
$row = mysql_fetch_array($postsresult);

 

from the code above how could i find out if row['event'] from each day of the month had a result...

 

so...

 

Su M  T W  Th F  Sa

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30

 

if the above is my calander and the 16th had an event i would want to show it by producing 16th with a link as it shows.

 

im just stuggling how to see if there is a result for each day itself

 

here is all my code for the calander

 

<script src="http://www.runningprofiles.com/jquery.js" type="text/javascript"></script>
<link href="http://www.runningprofiles.com/members/calendar/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<script src="http://www.runningprofiles.com/members/calendar/facebox/facebox.js" type="text/javascript"></script> 
<script>
jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
}) </script>

<?php
include '../../settings.php';



mk_drawCalendar($_GET['m'],$_GET['y']); 
  $m = (!$m) ? date("m",mktime()) : "$m";
    $y = (!$y) ? date("Y",mktime()) : "$y";
//*********************************************************
// DRAW CALENDAR
//*********************************************************
/*
    Draws out a calendar (in html) of the month/year
    passed to it date passed in format mm-dd-yyyy 
*/
function mk_drawCalendar($m,$y)
{
    if ((!$m) || (!$y))
    { 
        $m = date("m",mktime());
        $y = date("Y",mktime());
    }

    /*== get what weekday the first is on ==*/
    $tmpd = getdate(mktime(0,0,0,$m,1,$y));
    $month = $tmpd["month"]; 
    $firstwday= $tmpd["wday"];

    $lastday = mk_getLastDayofMonth($m,$y);

?>
<div align="center">
  <table cellpadding="2" cellspacing="0" border="1">
    <tr><td colspan="7" bgcolor="#00CCCC">
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
        <th bgcolor="#00CCCC"><font size=2><?="$month $y"?></font></th>
        <th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
        </tr></table>
    </td></tr>
    
    <tr><th width=22 class="tcell">Su</th><th width=22 class="tcell">M</th>
      <th width=22 class="tcell">T </th><th width=22 class="tcell">W</th>
      <th width=22 class="tcell">Th</th><th width=22 class="tcell">F</th>
      <th width=22 class="tcell">Sa</th></tr>
    
    <?php $d = 1;
    $wday = $firstwday;
    $firstweek = true;

    /*== loop through all the days of the month ==*/
    while ( $d <= $lastday) 
    {

        /*== set up blank days for first week ==*/
        if ($firstweek) {
            echo "<tr>";
            for ($i=1; $i<=$firstwday; $i++) 
            { echo "<td><font size=2> </font></td>"; }
            $firstweek = false;
        }

        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { echo "<tr>"; }

        /*== check for event ==*/  
	$sql = "SELECT * FROM events WHERE date='$d-$m-$y'";
	echo $sql;
$postsresult = mysql_query($sql);
$row = mysql_fetch_array($postsresult);
$num = mysql_num_rows($postsresult);
	if($row['event'] == 1)
    { echo "<td class='tcell'>";
        echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
        echo "</td>\n";

}

else {echo "<td class='tcell'>";
        echo "<a href=\"1\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
        echo "</td>\n";}
       

        /*== Saturday end week with </tr> ==*/
        if ($wday==6) { echo "</tr>\n"; }

        $wday++;
        $wday = $wday % 7;
        $d++;
    }
?>
    
    </tr>
  </table>
  Please select the date your event is held on.
  <br />
  
  <?php
/*== end drawCalendar function ==*/
} 




/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
    for ($tday=28; $tday <= 31; $tday++) 
    {
        $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
        if ($tdate["mon"] != $mon) 
        { break; }

    }
    $tday--;

    return $tday;
}

?>
</div>

Link to comment
https://forums.phpfreaks.com/topic/154485-solved-finding-results-from-a-row/
Share on other sites

here is a link http://www.runningprofiles.com/members/calendar/test.php#

so here is my db

 

CREATE TABLE IF NOT EXISTS `events` (
  `e_id` int(99) NOT NULL auto_increment,
  `e_event` varchar(50) NOT NULL default '',
  `e_start` datetime default NULL,
  `e_end` datetime default NULL,
  PRIMARY KEY  (`e_id`),
  KEY `e_start` (`e_start`,`e_end`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

 

 

so what i want to know is... how can i see if the date on the calander has a event... if so show a link if not show text.

 

the bold green part is what i cant figure outlol

If there's nothing scheduled for that date than it's going to have the default value...

 

  `e_event` varchar(50) NOT NULL default '',

 

which is an empty string.  So just check to see if the string isn't empty.

 

if($row['event'] != '')
{
    //add the link
}
else
{
    //add the day but not the with the link
}

I would select all the events for that month and put them into an array keyed by the date. So something like

 

SELECT `e_event` FROM `events` WHERE `e_start` > FIRST_DAY_OF_MONTH AND `e_start` < LAST_DAY_OF_MONTH

 

then loop that lot and create an events array like

 

$events['2009-01-03'] = true;

$events['2009-01-19'] = true;

 

You can do this before you start rendering your calendar.

 

Then when you're looping days and rendering your calendar you can call isset($events[$y.'-'.$m.'-'.$d]) to determine if there is an event on that particular day.

 

This way you will only need to make 1 sql query to your database. If you wish you could even set the link title="TITLE" field to the name of the event.

 

humm it not working :(

 

ok in db i have this

 

                                      event start                          event finish

6  testing event  2009-04-11 10:00:00  2009-04-11 11:00:00

 

$sql = "SELECT * FROM events WHERE e_start='$d-$m-$y'";
	echo $sql;
$postsresult = mysql_query($sql);
$row = mysql_fetch_array($postsresult);

	if($row['event'] != '')
{
    echo "<td class='tcell'>";
        echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
        echo "</td>\n";
}
else
{
    echo "<td class='tcell'>";
        echo "$d";
        echo "</td>\n";
}

 

 

what am i doing wrong

 

 

 

and soak thats just gone right over my head lol

Thats an elegant solution, soak.

 

Pseudo-code:

 

<?php

$q = 'select * from events where e_start = '...'';

$event_dates = array(); //hold the dates of the events

$result = mssql_query($q);
while ($row = mysql_fetch_assoc($result)) {
   print_r($row); //debug, remove when not testing
   $event_dates[$row['e_start']] = "hi my name is keeb and i want to be your friend";
}

print_r($event_dates); // debug, make sure it was populated

.
.
.
later on in mk_drawcalendar..


      if(array_key_exists($row['e_start'], $event_dates)) // is e_start in event_dates??
{
    // YES!
    print "woohoo it's there!";
    echo "<td class='tcell'>";
        echo "<a href=\"http://www.runningprofiles.com/test2.php?month=$d-$m-$y\" rel=\"facebox\" onClick=\"document.f.eventdate.value='$m-$d-$y';\">$d</a>";
        echo "</td>\n";
}
else
{
    print "crap there's no event ";
    echo "<td class='tcell'>";
        echo "$d";
        echo "</td>\n";
}
?>

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.