Rahul Pamnani
Rahul Pamnani

Reputation: 1435

I want to show available time and booked time to the user

I am working on booking scheme in which i want to show user whether time slots on selected date is available or booked.

 <td style="border:1px solid;padding:11px;">
<?php   

        $query5=mysql_query("select * from doctorbooking where aday='".$_REQUEST['date']."'");

        $query6=mysql_fetch_array($query5);

        echo $query6['atime'];
?>
if($query6>0)
{
<?php echo $array_of_time[$key].' - '.$array_of_time[$key+1]; ?><br /><span style="color:red;"><?php echo "Booked"; ?></span> 
}
else
{
<?php echo $array_of_time[$key].' - '.$array_of_time[$key+1]; ?><br /><span style="color:red;"><?php echo "Available"; ?></span>
}


</td>

First I have selected data from the database on selected date.It is showing booked and available both.I think i have applied if else condition in wrong way.Thanks in advance.

Upvotes: 1

Views: 265

Answers (1)

JazZ
JazZ

Reputation: 4579

The $query6 is an array so you'll have to loop to be capable to apply the if/else condition. Also, there are syntax errors with php and html tags.

Something like this should work (not tested) :

<td style="border:1px solid;padding:11px;">
    <?php
        $query5 = mysql_query("select * from doctorbooking where aday = '" . $_REQUEST['date'] . "'");
        $query6 = mysql_fetch_array($query5);

        var_dump($query6); // Use var_dump() function since $query6 is an array

        foreach ($query6 as $key => $value) { // Use foreach to loop through $query6 array
            if ($value > 0) {
                echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;">Booked</span>';
            } else {
                echo $array_of_time[$key] . ' - ' . $array_of_time[$key+1] . '<br /><span style="color:red;">Available</span>';
            }
        }
    ?>
</td>

Hope it helps.

PS : be carefull, the var $array_of_time is not defined in your code.

Upvotes: 1

Related Questions