PHP echoing the wrong number of columns in HTML table

hello everyone,

I have a PHP query:

$sql = mysqli_query($conn, "SELECT ip
                                 , host
                                 , page 
                                 , DATE_FORMAT(date, '%m/%d/%y') as date
                                 , TIME_FORMAT(time, '%T') as time
                            FROM tblTraffic 
                            ORDER BY date DESC, time DESC");

and I’m echoing out the results in this code:

        // printing table rows
        while($row = mysqli_fetch_row($sql)) {
            echo '<tr>'; 
            foreach ($row as $key => $col) {
				echo "<td>$col</td>"; }
            echo '</tr>';

however, in the attached image you can see what I’m getting as an output. I don’t think my code is wrong. Can someone here maybe see something that is wrong with this?



cant see the image (waaay too small to be worth anything)

how about trying to explain what we are looking at?

What is going on? (results)
What you want? (expected results)

can’t you right click on the image and “save as”, download it to your machine and look at it there? I did and it is of proper size.

This is what I get:

  1. 6 columns when there’s only 5 being echoed. Columns headers are: “VISITOR IP ADDRESS, ISPNAME”, “VISITOR DOMAIN ADDRESS”, “BLANK”, “PAGE VISITED”, “DATE”, “TIME”.
  2. the PAGE VISITED data appears in column 3 which has a BLANK header, the DATE data appears in column 4 which has a header saying 'PAGE VISITED", the TIME data appears in column 5 which has a header saying DATE and column 6 has no data but has a header that says TIME.

This is what I want:

  1. The table output just like my code shows: 5 columns - “VISITOR IP ADDRESS, ISPNAME”, “VISITOR DOMAIN ADDRESS”, “PAGE VISITED”, “DATE”, “TIME”, with all column headers centered in the middle of their table cells and the appropriate data in the correct columns.


The html markup for your table heading section contains a mistake.

1 Like

thank you so much for pointing that out! it works perfectly now. what a simple issue. :roll_eyes:

Sponsor our Newsletter | Privacy Policy | Terms of Service