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
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 ?

Link to comment
Share on other sites

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

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.