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>';
} 
?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';
} 
?>

 

 

Link to comment
Share on other sites

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 ;

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

For a calendar type of application, using varchar is useless.

 

You need to learn either Unix timestamps or MySQL timestamps.  Don't worry too much about formatting it, that is the easy part.

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.