Drop Down Based on Current Day

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Drop Down Based on Current Day

Post 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> ';
 
?>
 
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Drop Down Based on Current Day

Post 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";
Post Reply