Jump to content

[SOLVED] nedd assistance with calendar script


kb9yjg

Recommended Posts

Hey all,

 

I have a script that creates time increments dynamically and should be displaying columns right though  Any ones help is greatly appreciated. Code is below.

<?
$stime = strtotime('12am'); 
for ($i = 0; $i < (24 * 4); $i++) { 
    $tod = $stime + ($i * 30 * 60); 
    $display = date('h:i A', $tod); 
    if (substr($display, 0, 2) == '00') { 
        $display = '12' . substr($display, 2); 
    } 
include('inc/connect.inc');
$table="events";
$columns = 7;
$current_column = 1;	
$cols=7;
if ($current_column == 1) {
        echo '<tr><td scope=row align=center>'.$display.'</td>';
    }

$q="select * from $table";
$res=mysql_query($q) or die("Error selecting events. ".mysql_error());
while($row=mysql_fetch_assoc($res)){
if($display=$row['evtime']){
echo '<td align="center"><a title="'.$row['eday'].'<br />'.$row['evtime'].'<br />'.$row['about'].'">'.$row['event'].'</a></td>';
	$current_column++;
if ($current_column > $columns) {
        echo "</tr>";
        $current_column = 1;
    }else{ echo '<td> </td>';
  }
  }else{echo '<td> </td>';}
}
}
if ($current_column>1) {
    for ($col=$current_column; $col<=$columns; $col++) {
        echo "<td> </td>";
    }
echo '</tr>';
} 
?>

 

 

What it does:

 

populates each time slot with the same post

it skips the date it is supposed to be posted on

 

Does not do:

does not fill in accordingly all other timeslots and columns with spaces since theres no data for those cols or slots

Does not stick the time and event in the correct time slot

 

What i want it to do.

 

Fill in all other columns and time slots with spaces so that there are no empty cells

stick the event on the correct date and time

 

This is a weekly event calendar and need to have each column either filled with events or spaces indicating no event is scheduled.

as seen on my original post of this thread

<?
$stime = strtotime('12am'); 
for ($i = 0; $i < (24 * 4); $i++) { 
    $tod = $stime + ($i * 30 * 60); 
    $display = date('h:i A', $tod); 
    if (substr($display, 0, 2) == '00') { 
        $display = '12' . substr($display, 2); 
    } 
include('inc/connect.inc');
$table="events";
$columns = 7;
$current_column = 1;	
$cols=7;
if ($current_column == 1) {
        echo '<tr><td scope=row align=center>'.$display.'</td>';
    }

$q="select * from $table";
$res=mysql_query($q) or die("Error selecting events. ".mysql_error());
while($row=mysql_fetch_assoc($res)){
if($display=$row['evtime']){
echo '<td align="center"><a title="'.$row['eday'].'<br />'.$row['evtime'].'<br />'.$row['about'].'">'.$row['event'].'</a></td>';
	$current_column++;
if ($current_column > $columns) {
        echo "</tr>";
        $current_column = 1;
    }else{ echo '<td> </td>';
  }
  }else{echo '<td> </td>';}
}
}
if ($current_column>1) {
    for ($col=$current_column; $col<=$columns; $col++) {
        echo "<td> </td>";
    }
echo '</tr>';
} 
?>

 

 

Here is my table structure. I only am using a single table for this calendar.

CREATE TABLE `events` (
  `eid` int(11) NOT NULL auto_increment,
  `evtime` varchar( NOT NULL,
  `eday` varchar(10) NOT NULL,
  `event` varchar(100) NOT NULL,
  `about` text NOT NULL,
  PRIMARY KEY  (`eid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

 

 

stored it like that because I had some bad luck with formatting dates in previous scripts. I found if they were stored in varchar they could easily be formatted or manipulated. I am willing to learn and figure out why this isn't  working though. Thank you for your time in going through this with me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.