Page 1 of 1

Drop Down Based on Current Day

Posted: Tue Feb 10, 2009 8:42 pm
by cupaball
Hi All:

I have just about give up on this. I am trying to create a drop down whose selection based on the current day. here is the code i keep getting Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\date2\index.php on line 21 (in the example it is line #20)

Code: Select all

 
<?
require("connection.php");
 
    $q = "SELECT `tb_day_of_week`.`id`, `tb_day_of_week`.`day_of_week`\n"
    . "FROM `tb_day_of_week`\n"
    . "ORDER BY `tb_day_of_week`.`id` ASC\n"
    . " LIMIT 0, 30 ";
 
    $result = $mysqli->query($q) or die($mysqli_error($mysqli));
 
   print '<select name="weekend">';
 
     if($result) {
        while($row = $result->fetch_object()) {
        $id = $row->id;
        $day = $row->day_of_week;
 
        print '
        <option value="'.$id.'"'.
        if ($id == $daynum) {
 
 
        print 'selected';
 
 
 
        }.'>'.$day.' </option>';
 
        }
     }
     print '</select> ';
 
?>
 

Re: Drop Down Based on Current Day

Posted: Tue Feb 10, 2009 10:09 pm
by requinix
You can't just shove an if block where you want.

Code: Select all

// bad
$text = "These are " . if ($green) { "green " } . "apples";
 
// good
$text = "These are ";
if ($green) $text .= "green ";
$text .= "apples";