954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem with While Loop Echoing Rows

Hi,

The following code is working without errors:

<table>
                    <tr>
                        <td>Booking No.</td>
                        <td>Driver Id</td>
                        <td>Time Booked</td>
                        <td>From</td>
                        <td>Pick Up Time</td>
                        <td>To</td>
                        <td>No. of Passengers</td>
                        <td>Distance</td>
                        <td>Cost</td>
                    </tr>
                    <?php
                        $stmt = $dbh->prepare("SELECT * FROM Booking
                          WHERE cust_id = '$username'
                          ");
                        $stmt->execute();
                        
                        
                        while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
                            echo "<tr><td>".$row['booking_no']."</td>".
                                 $row['driver_id']."</td>".
                                 $row['time_booked']."</td>".
                                 $row['pick_up_dest']."</td>".
                                 $row['pick_up_time']."</td>".
                                 $row['arrive_dest']."</td>".
                                 $row['no_of_passengers']."</td>".
                                 $row['distance']."</td>".
                                 $row['cost']."</td></tr>";
                        }
                    ?>
                </table>


However rather than the field headings being displayed above the rows each piece of data is appearing above the field headings apart from the booking_no. The output is like this:

driverneil2012-01-28 01:00:00Oxford2012-01-28 01:30:00London21540.00
Booking No. 	Driver Id 	Time Booked 	From 	Pick Up Time 	To 	No. of Passengers 	Distance 	Cost
000001


Anyone know why this is happening?

Also is there a better way of outputting this data using PDOs?

Thanks in advance.

BenzZz
Junior Poster
116 posts since Feb 2011
Reputation Points: 10
Solved Threads: 6
 

You are missing 's.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

You are missing 's.

LOL what a silly mistake, guess that is what tiredness does to you!

Thanks.

BenzZz
Junior Poster
116 posts since Feb 2011
Reputation Points: 10
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: