Comdemned Posted May 3, 2008 Share Posted May 3, 2008 I have a problem where I have 2 similar If statments and only one is working as expected. I have put comments in capitals next to each statement in question The first if statement only works on the last record in the table as the 3rd if statement works on all records in the table. Any insite into why this is happening is greatly appricated. <?php if ($newdate > ($row['date_time']-$row3['timeframe']) && $newdate < ($row['date_time'])){ // THIS ONLY WORKS ON THE LAST RECORD IN THE TABLE $string = " bgcolor=#00FF00> "; } elseif ($newdate > ($finish_time+($a*86400))-($row3['timeframe'])){ // THIS ONE WORKS FINE $string = " bgcolor=#00FF00> "; } elseif ($newdate >= $row['date_time'] && $newdate < ($row['date_time']+$row2['timeframe']+$row['extra_time'])){ // THIS WORKS ON EACH RECORD IN THE TABLE (EXACTLY HOW ITS MENT TOO) if ($newdate == $row['date_time']){ $string = " bgcolor=#FF0000>" . $row1['firstname'] . " " . $row1['surname'] . "<br>" . $row2['name'] . "<br> <a href=\"" . $_SERVER['PHP_SELF'] . "?option=appointment&type=view&app_id=" . $row['app_id'] . "\">View</a><br> <a href=\"" . $_SERVER['PHP_SELF'] . "?option=appointment&type=edit&app_id=" . $row['app_id'] . "\">Edit</a><br> <a href=\"" . $_SERVER['PHP_SELF'] . "?option=appointment&type=delete&app_id=" . $row['app_id'] . "\">Delete</a>"; } else { // RED CELL $string = " bgcolor=#FF0000> "; } break; } else { $string = " bgcolor=#00FF00>" . date('l d M Y g:i a',$newdate) . " <a href=\"" . $_SERVER['PHP_SELF'] . "?option=appointment&type=new&newdate=$newdate&app_stage=3&type_id=$type_id&client_id=$client_id\">Book</a> <br>"; } ?> Thanks in advance. Murray Quote Link to comment https://forums.phpfreaks.com/topic/103979-solved-2-if-statments-with-different-results/ Share on other sites More sharing options...
Barand Posted May 3, 2008 Share Posted May 3, 2008 Perhaps the last row is the only one where that condition is true. Quote Link to comment https://forums.phpfreaks.com/topic/103979-solved-2-if-statments-with-different-results/#findComment-532323 Share on other sites More sharing options...
Comdemned Posted May 3, 2008 Author Share Posted May 3, 2008 <?php if ($newdate > ($row['date_time']-$row3['timeframe']) && $newdate < ($row['date_time'])){ // THIS ONLY WORKS ON THE LAST RECORD IN THE TABLE $string = " bgcolor=#00FF00> "; } ?> Basicly what I want this to do is every $newdate between $row['date_time']-$row['timeframe'] and $row['date_time'] is a different colour So there for the condition should be true for each row in the table, the only variable that changes each time the script is run is the length of the timeframe. Quote Link to comment https://forums.phpfreaks.com/topic/103979-solved-2-if-statments-with-different-results/#findComment-532325 Share on other sites More sharing options...
sasa Posted May 3, 2008 Share Posted May 3, 2008 can we see loop part Quote Link to comment https://forums.phpfreaks.com/topic/103979-solved-2-if-statments-with-different-results/#findComment-532369 Share on other sites More sharing options...
Comdemned Posted May 3, 2008 Author Share Posted May 3, 2008 Ive fixed it now. I needed to add a break; after the string line in the if statement that was playing up. the working code is <?php if ($newdate > ($row['date_time']-$row3['timeframe']) && $newdate < ($row['date_time'])){ // THIS ONLY WORKS ON THE LAST RECORD IN THE TABLE $string = " bgcolor=#00FF00> "; break; } ?> that way when it found something that was true with the loop it stoped and didnt follow on with the rest of the elseif statements. Quote Link to comment https://forums.phpfreaks.com/topic/103979-solved-2-if-statments-with-different-results/#findComment-532416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.