0

I am having a Problem in this code : `

                 <?php echo "Choose a date"; 
                     $reservation_date = $rm->retrieveReservation(); 
                              $data_date = array();
                              while($row_date = mysql_fetch_assoc($reservation_date)){
                                array_push($data_date, $row_date);
                                $dateOptions = ""
    .                               "<select class='filter'>"
    .                                  "<option value='<?php echo $row['date']  ; ?>'><?php echo $row['date']  ; ?></option>"
    .                               "</select>";
                                echo $dateOptions;
                              } ?>

                           ?>

I want to output Sql row values in a dropdown menu. Thanks in advance!

4
  • Apart from the PHP syntax error, what else happens? Commented May 14, 2014 at 7:11
  • It's just keep on saying Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in Commented May 14, 2014 at 7:12
  • one of problem is in here: ` $dateOptions = "" . "<select class='filter'>" . "<option value='{$row['date']}'>{$row['date']}</option>" . "</select>";` Commented May 14, 2014 at 7:13
  • 1
    I think there are multiple problems there.. Commented May 14, 2014 at 7:14

3 Answers 3

1

You don't have to echo the <select> in the while, you should do like that :

 <?php echo "Choose a date"; 
                 $reservation_date = $rm->retrieveReservation(); 
                          $data_date = array();
                          $dateOptions = "<select class='filter'>";
                          while($row = mysql_fetch_assoc($reservation_date)){
                            array_push($data_date, $row_date);
                            $dateOptions = "<option value='". $row['date']."'>". $row['date'] ."</option>";
                          } ?>
                          $dateOptions = "</select>";
                          echo $dateOptions;
                       ?>
Sign up to request clarification or add additional context in comments.

1 Comment

@tomjerry - Hi newuser you should accept the correct answer. You should click on ckeck mark onleft side of each question.
0

This should work:

echo "<select class='filter'>";
while($row = mysql_fetch_assoc($reservation_date)){
    echo "<option value='".$row['date']."'>".$row['date']."</option>";
}
echo "</select>";

You need to have your select tag outside of the loop. You also had a bunch of syntax errors in your PHP.

Comments

0
 <?php echo "Choose a date"; 
       echo "<select class='filter'>";
       $reservation_date = $rm->retrieveReservation(); 
              $data_date = array();
              while($row_date = mysql_fetch_assoc($reservation_date)){
                  array_push($data_date, $row_date);
                  $dateOptions = "<option value='{$row['date']}'>{$row['date']}</option>";
                  echo $dateOptions;
              } 
       echo  "</select>";
 ?>

may this code will work for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.