patokun
patokun

Reputation: 113

Condition won't work properly

This is driving me insane! Basically it's a reservation form. I want the client to be able to reserve only 2 hours away (before or after) an existing reservation of another client. But for some reason it's not working! It keeps giving me not available even thogh the times are very far apart...

rtime is reserved time by another client, trtime is the time of the reserved by the current client.

<?php
$rtime = 3.5;
$trtime = 10;

echo '</br>trtime: '.$trtime.'</br>rtime:  '.$rtime.'</br>';

if( ((rtime+2)<=trtime) 
        && ((trtime-2)>=rtime) )
    $available = true;
else
    $available = false;


if($available)
{
    echo '<p>Table has been found and reserved</p>';
}
else
    echo'<p>No reservation found</p>';


?>

Upvotes: 0

Views: 66

Answers (1)

designosis
designosis

Reputation: 5263

Don't you mean ...

    if( (($rtime+2)<=$trtime) 
            && (($trtime-2)>=$rtime) )
        $available = true;
    else
        $available = false;

... ? (note the $ in the stringname)

Upvotes: 5

Related Questions