Jump to content

[SOLVED] 2 if statments with different results


Comdemned

Recommended Posts

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

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

 

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.

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.