0

Any idea why this only loops through once? I am trying to have nested panels for each result from the DB. I know there are probably a lot of bad practices here, but I just need it to work for a class. This is never going into production.

while($row = mysql_fetch_array($result)) {

    echo sizeof($row);

    $resId=$row[reservationId];
    $counter++;

    try {
        $startDate = new DateTime($row[startDate]);
    } catch (Exception $e) {
        echo $e->getMessage();
        exit(1);
    }
    try {
        $endDate = new DateTime($row[endDate]);
    } catch (Exception $e) {
        echo $e->getMessage();
        exit(1);
    }
    echo "
    <div class=\"panel-group\" id=\"accordion".$counter."\">
    <div class=\"panel panel-default\">
    <div class=\"panel-heading\">
    <h4 class=\"panel-title\"><a class=\"panel-toggle\" data-toggle=\"collapse\" data-parent=\"#accordion".$counter."\" href=\"#collapseInner".$counter."\"><label> ".$row[title]." </label> <label class=\"pull-right\">".$startDate->format('m-d-Y')."</label></a></h4>
    </div>
    <div id=\"collapseInner".$counter."\" class=\"panel-body collapse\">
        <div class=\"panel-inner\">
    <div class=\"col-lg-8\">
    <p><label>Lodging Reservation #:01-".$row[reservationId]."</label></p>
    <p><label>Check In: ".$startDate->format('m-d-Y')."</label></p>
    <p><label>Check Out: ".$endDate->format('m-d-Y')."</label></p>
    </div>
    <div class=\"col-lg-4\">
    <button type=\"submit\" class=\"btn btn-primary btn-lg\" data-toggle=\"modal\"
        data-target=\"#myModal".$counter."\">
    Edit Reservation</button>
     <!-- Modal -->
        <div class=\"modal fade\" id=\"myModal".$counter."\" tabindex=\"-1\"
        role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">
    <div class=\"modal-dialog\">
        <div class=\"modal-content\">
    <div class=\"modal-header\">
        <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria
        hidden=\"true\">&times; </button>
        <h4 class=\"modal-title\" id=\"myModalLabel\">Edit Reservation</h4>
        </div>
    <div class=\"modal-body\">
    <form method=\"post\" action=\"../controller/EditLodgingReservation.php?
        rId=".$resId."&counter=".$counter."\">
    <label>Select Dates:</label>
    <div class=\"input-group\">
    <div class=\"input-group-addon\">
    <i class=\"fa fa-calendar\"></i>
    </div>
    <input type=\"text\" class=\"form-control pull-right\" 
        id=\"reservation".$counter."\" name=\"reservation".$counter."\">
    </div><!-- /.input group -->
    <label>Select Lodging</label>
    <select multiple=\"\" class=\"form-control\" id=\"lodgingList".$counter."\" 
        name=\"lodgingList".$counter."\">
    ";

    $result = getlodging();
    while($row = mysql_fetch_array($result)) {
        echo "<option value=".$row[lodgingId].">".$row[title]." -- $".$row[ratePerDay]." 
          /night</option>";
    }
    echo"
    </select>
    </div>
    <div class=\"modal-footer\">
    <button type=\"button\" class=\"btn btn-default\" data-
        dismiss=\"modal\">Close</button>
    <button type=\"submit\" class=\"btn btn-primary\">Save changes</button></a>
    </div>
     </form>
    </div>
    </div>
    </div>
     <p></p>
     <form method=\"post\" action=\"../controller/DeleteLodgingReservation.php?
     rId=".$resId."&pId=".$personId."\">
     <button type=\"submit\" class=\"btn btn-danger btn-lg\">Delete Reservation</button>
     </form>
    </div>
    </div>
    </div>
    </div>
    </div>";    
}
?>
3
  • 1
    For starters, why are you calling while($row = mysql_fetch_array($result)) { twice? Commented May 6, 2014 at 15:08
  • Quoting $row keys would be nice as well ;) Commented May 6, 2014 at 15:10
  • @John you were on the right track. They are both there because I am populating a select box with info from the DB on the form. Commented May 6, 2014 at 15:19

1 Answer 1

3

You are overwriting your first $row variable with your second while loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow thank you. I can't believe I missed that. I guess my brain has had it.

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.