Jump to content

Dont understand why its repeating weeks


deansaddigh

Recommended Posts

I have this bit of code,which basically looks to see if the course matches what we are looking for then define itsmin and max weeks.

[code

						//deans changes 
						/**************************************************/
						if($coursetitle == 'IELTS Exam Preparation')
						{
							$maximum = 48;	

							for($week=4; $week<= $maximum; $week+=4)	
						    {
						   		echo '<option>'.$week.'</option>';
						   	}
						}

						/*************************************************/

 

Simpl right, well if u go here http://www.cisukschool.co.uk/booknow.php?CourseTitle=IELTS Exam Preparation it goes from o4 to 48 in increents of 4 then iafter 48 it goes to2 and ten 48 again, any ideas?

Link to comment
https://forums.phpfreaks.com/topic/196597-dont-understand-why-its-repeating-weeks/
Share on other sites

Dear god i am so sorry for the last posts rediculous spelling mistakes, for some reason the box was jumping up and down as i was writing, and hence couldnt' see, my appolagise

 

Hi, i think i know whats going on. what im basically trying to do is if a certain course is selected it will show on the form under duration in weeks,  what ever i set it, however the if statments are re-writing over each other, if the senario isnt met.

heres the whole code

 

	//Trim the course titles. 
                          	$coursetitle = trim($coursetitle);
                          	
                          	if ($coursetitle == 'Business English')
						{
							$maximum = 2;

						} 
						else
						{
							$maximum = 48;
						}

						//deans changes 
						/**************************************************/
						if($coursetitle == 'IELTS Exam Preparation')
						{
							$maximum = 48;	

							for($week=4; $week<= $maximum; $week+=4)	
						    {
						   		echo '<option>'.$week.'</option>';
						   	}
						}
						else 
						{
       	                	for($week=2; $week<= $maximum; $week+=1)	
						    {
						   		echo '<option>'.$week.'</option>';
						   	}
						}	

						/***********************************************/

						if($coursetitle == 'IELTS Foundation Test course')
						{
							$maximum = 48;	

							for($week=4; $week<= $maximum; $week+=4)	
						    {
						   		echo '<option>'.$week.'</option>';
						   	}
						}
						else 
						{
       	                	for($week=2; $week<= $maximum; $week+=1)	
						    {
						   		echo '<option>'.$week.'</option>';
						   	}
						}	

 

as you can see the else statments are messing each other up.

 

Can you show me how i can do it pretty please ?

Well sure but I'm gonna need some more info because your code does not make a lot of sense like what are the "else" for?

 

When I rewrite it I get:

 

$course_title = trim($course_title);

$course_maxweeks = 48;
if ('Business English' === $course_title) {
   $course_maxweeks = 2;//??
}

else if ('IELTS Exam Preparation' === $course_title) {
    for ($week = 4; $week <= $course_maxweeks; $week += 4) {
        echo '<option>', $week, '</option>';
    }
}

else if ('IELTS Foundation Test Course' === $course_title) {
    for ($week = 4; $week <= $course_maxweeks; $week += 4) {
        echo '<option>', $week, '</option>';
    }
}

else {
    for ($week = 2; $week <= $course_maxweeks; ++$week) {
        echo '<option>', $week, '</option>';
    }
}

 

Notice the question marks on top

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.