PHP's code question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

PHP's code question

Post by phpbluee »

I've the following code, there is an error but I can't quite figure it out. If someone see something wrong with the code, please shed some light. Thanks...
P.S. I think the error is around the string $suffix.

Code: Select all

		<?
		
		$startHourOfWeekPlanner = 8;	// Start hour of week planner
		$endHourOfWeekPlanner = 21;	// End hour of weekplanner.
		
		$date = mktime($startHourOfWeekPlanner,0,0,5,5,2006);
		for($no=$startHourOfWeekPlanner;$no<=$endHourOfWeekPlanner;$no++){
			
			$hour = $no;
			
			// Remove these two lines in case you want to show hours like 08:00 - 23:00
			$suffix = date("a",$date);
			$hour = date("g",$date);
			
			// $suffix = "00"; // Enable this line in case you want to show hours like 08:00 - 23:00 
			
			$time = $hour."<span class=\"content_hour\">$suffix</span>";	
			$date = $date + 3600;		
			?>
			<div class="calendarContentTime"><? echo $time; ?></div>
			<?			
		}
		?>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP's code question

Post by fugix »

what is the exact error that you are receiving?
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

Re: PHP's code question

Post by phpbluee »

[text]
I can't seem to post screen capture here. But here the text error below. Thanks.

$suffix"; $date = $date + 3600; ?>
[/text]
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: PHP's code question

Post by Peter Kelly »

Code: Select all

<?
                
                $startHourOfWeekPlanner = 8;    // Start hour of week planner
                $endHourOfWeekPlanner = 21;     // End hour of weekplanner.
                
                $date = mktime($startHourOfWeekPlanner,0,0,5,5,2006);
                for($no=$startHourOfWeekPlanner;$no<=$endHourOfWeekPlanner;$no++){
                        
                        $hour = $no;
                        
                        // Remove these two lines in case you want to show hours like 08:00 - 23:00
                        $suffix = date("a",$date);
                        $hour = date("g",$date);
                        
                        // $suffix = "00"; // Enable this line in case you want to show hours like 08:00 - 23:00 
                        
                        $time = $hour."<span class='content_hour'>$suffix</span>";    
                        $date = $date + 3600;    
                        ?>
                        <div class="calendarContentTime"><? echo $time; ?></div>
                        <?                      
                }
                ?>
Try that
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

Re: PHP's code question

Post by phpbluee »

Hi Peter, you posting contain some #39, #40, #41 and etc... What are they represent?
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

Re: PHP's code question

Post by phpbluee »

I tried that and it's still not working.
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: PHP's code question

Post by Peter Kelly »

Sorry I used quick reply and it seemed to have buggered it up try this.

Code: Select all

                <?
                
                $startHourOfWeekPlanner = 8;    // Start hour of week planner
                $endHourOfWeekPlanner = 21;     // End hour of weekplanner.
                
                $date = mktime($startHourOfWeekPlanner,0,0,5,5,2006);
                for($no=$startHourOfWeekPlanner;$no<=$endHourOfWeekPlanner;$no++){
                        
                        $hour = $no;
                        
                        // Remove these two lines in case you want to show hours like 08:00 - 23:00
                        $suffix = date("a",$date);
                        $hour = date("g",$date);
                        
                        // $suffix = "00"; // Enable this line in case you want to show hours like 08:00 - 23:00 
                        
                        $time = $hour."<span class='content_hour'>$suffix</span>";    
                        $date = $date + 3600;    
                        ?>
                        <div class="calendarContentTime"><? echo $time; ?></div>
                        <?                      
                }
                ?>
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

Re: PHP's code question

Post by phpbluee »

Sorry, it still not working. It doesn't like the following line for some reason when I did a view source.

Code: Select all

                        $time = $hour."<span class='content_hour'>$suffix</span>";    

Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: PHP's code question

Post by Peter Kelly »

It works fine for me.

Code: Select all

<?

$startHourOfWeekPlanner = 8; // Start hour of week planner
$endHourOfWeekPlanner = 21; // End hour of weekplanner.

$date = mktime($startHourOfWeekPlanner, 0, 0, 5, 5, 2006);
for ($no = $startHourOfWeekPlanner; $no <= $endHourOfWeekPlanner; $no++)
{

$hour = $no;

// Remove these two lines in case you want to show hours like 08:00 - 23:00
$suffix = date("a", $date);
$hour = date("g", $date);

// $suffix = "00"; // Enable this line in case you want to show hours like 08:00 - 23:00

$time = $hour . "<span class='content_hour'>$suffix</span>";
$date = $date + 3600;

?>
<div class="calendarContentTime"><?

echo $time;

?></div>
<?

}

?>
shows in the source view

Code: Select all

<div class="calendarContentTime">8<span class='content_hour'>am</span></div> 
<div class="calendarContentTime">9<span class='content_hour'>am</span></div> 
<div class="calendarContentTime">10<span class='content_hour'>am</span></div> 
<div class="calendarContentTime">11<span class='content_hour'>am</span></div> 
<div class="calendarContentTime">12<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">1<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">2<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">3<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">4<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">5<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">6<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">7<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">8<span class='content_hour'>pm</span></div> 
<div class="calendarContentTime">9<span class='content_hour'>pm</span></div>
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP's code question

Post by fugix »

to answer your question from before blue...the &#40 and &#41 are HTML's way of inserting parenthesis.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP's code question

Post by fugix »

#40 and #41...changed them to actual parenthesis above
phpbluee
Forum Newbie
Posts: 7
Joined: Sat Apr 16, 2011 9:22 pm

Re: PHP's code question

Post by phpbluee »

Humm, I don't know what's going on here. I downloaded WAMP and installed on my local computer and run this script from there. I don't know if there is anything that causes this to not work. If anyone else know anything please post some tips. Thanks... :(
Post Reply