Jump to content

trying to write if statement


jimfog
 Share

Recommended Posts

Here is what i am trying to do:

          if ($i < $startday-1)             echo "<td></td>\n";          else {             echo "<td class='calendar-day' align='center' valign='middle' height='30px'>" . ($i - $startday + 2) . "</td>\n";         }      if($i < $sunday)echo "<td></td>\n";          else {             echo "<td class='calendar-day' align='center' valign='middle' height='30px'>" . ($i - $startday -1) . "</td>\n";         }

Above you see the logic-how am i going to combine all of the above in a successful if statement-the above prints a mess.I am just puting it here so that you can understand my logic, read it carefully, if you cannot get a meaning out of it i will try sth else to show you.

Link to comment
Share on other sites

im not sure what exactly what you are asking for. how to optimize it? Is there a specific bug you are encountering? it's not immediately the context of the code snippet you are providing, so it's not really easy to say why it may not be working.

Edited by thescientist
Link to comment
Share on other sites

I am going to restate the problem somewhat differently so that you can understand what i am talking about.I will go step by step. We have these 2 expressions:

($i < $startday-1)||($i<$sunday))

Either of these is true i want the following output:

echo "<td></td>\n";

So, summing it up:

(($i < $startday-1)||($i<$sunday))echo "<td></td>\n";

So far is straightforward i think. From here the problem arises. here is what i want to achieve: if($i < $startday-1) is false i want the following output:

echo "<td class='calendar-day' align='center' valign='middle' height='20px'>" . ($i - $startday + 2) . "</td>\n";

and if ($i<$sunday) is false i want THIS output:

echo "<td class='calendar-day' align='center' valign='middle' height='20px'>" . ($i - $startday + 2) . "</td>\n";

the latter, being different than the above, as seen evident. Have you got it now?

Link to comment
Share on other sites

seems like you know what you want and how to write it. I'm still not sure what the issue is. have you tried using psuedo code to try and think out your logic?

if(condition A === true || condition B === true){  //code}else{  if(condition A !== true){    //code  }else if(condition B !== true){    //code  };

Link to comment
Share on other sites

No it does not work,,maybe i should explain the whole story.I am in the process of making a calendar, the portion that appears when someone goes to hotmail calendar, looks at the left and sees this:https://skydrive.live.com/redir.aspx?cid=be27434b2aac8130&resid=BE27434B2AAC8130!224&parid=BE27434B2AAC8130!140 The problem i am facing is with the printing of the days and more specifically when the month starts at sunday(something which happens for example on April).Here is March(which is ok):https://skydrive.live.com/redir.aspx?cid=be27434b2aac8130&resid=BE27434B2AAC8130!225&parid=BE27434B2AAC8130!140 And here is the problem(April):https://skydrive.live.com/redir.aspx?cid=be27434b2aac8130&resid=BE27434B2AAC8130!226&parid=BE27434B2AAC8130!140The correct would be if 1 went under sunday and NOT monday as depicted in the above photo. here is the code, not whole of it, but the one which is specific about printing the days.

for ($i = 0; $i < (($maxday-1) +$startday); $i++) {		 if (($i % 7) == 0)// όταν η μέρες είναι 7 στον αρθμό άνοιξε row			 echo "<tr class='juveline'>\n";						 if ($i < $startday-1)			 echo "<td></td>\n";		 else {			 echo "<td class='calendar-day' align='center' valign='middle' height='20px'>" . ($i - $startday + 2) . "</td>\n";		 }				 if (($i % 7) == 6)			 echo "</tr>\n";	 }

P.S The monthname are in Greek, so do not be confused with it.

Link to comment
Share on other sites

You need to do a check inside the loop to see if you are on the first day of the month. If you're on the first day, then you need another loop inside that one to draw out all of the days from the previous month so that the first of the month starts on the right day. So you need to figure out which day the first is on, and if it's not the first day in your calendar week then you need to draw out enough empty boxes to put the first where it needs to be. So that is one if statement inside your loop, you need to check if the current day is the first of the month and write out the extra empty boxes if so. Then, you write the cell for the current day, which you do for all days (this is after the previous if statement). After you write the cell for the current day then you need another if statement to check if the current day is the last day of the month, and if it doesn't fall on the last day of the week then you need to have another loop where it writes out more empty boxes until the end of week. Those represent the first days in the following month. Then you can do your check to write out the </tr> and end the loop. e.g.:

for (...){  //check to write out <tr>   if (the current day is the first of the month)  {    for (number of days between the first of the week and the current day)      // write empty day  }   // write current day   if (the current day is the end of the month)  {    for (number of days between the current day and the end of the week)      // write empty day  }   // check to write out </tr>}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...