0

I have two sql tables I'm reading from and I would like to display each table as its own, separate table. First the internal, and then the external. And I'd like to have a simple title prefacing each one. For instance:

INTERNAL

Table here

EXTERNAL

Table here

What's happening though is the INTERNAL and EXTERNAL titles keep appearing on the same line, or both come before the tables. Like this:

INTERNAL

EXTERNAL

Internal Table here
External Table here

I've tried including the titles as part of the php tags. Those are the currently commented out lines. And I've also tried adding the html outside of the php tags like this:

<br><br>
<b>INTERNAL</b>
<br><br>

<?php Internal Table here ?>

And then:

<br><br>
<b>EXTERNAL</b>
<br><br>

<?php External Table here ?>

But that still results in both titles appearing first, before the tables. Does the html get processed prior to the php? I must be interpreting this too linearly, like a script because it's certainly not being processed in the order in which it is coded on my page.

This is my code as is, which has the titles commented out. The tables appear sandwiched together which tells me they are not being interpreted as two distinct elements on the page. Do I need to put each one in it's own tag?

<?php
    $internal = getInternalNetworkTable();
    if ($internal->num_rows > 0){


            //echo " <b>INTERNAL</b>";
            echo "<table cellspacing=\"0\">";
            echo "<tr>";
            echo " <th><b>Device</b></th>"; 
            echo " <th><b>Label</b></th>";
            echo " <th><b>Address</b></th>";
            echo " <th><b>Type</b></th>";
            echo " <th><b>DisplayNumber</b></th>";
            echo " <th><b>Wiki</b></th>";
            echo "</tr>";
            while ($row = $internal->fetch_assoc()){
                    echo "<tr>";
                    echo ("<td>" . $row["Device"] ."</td>");
                    echo ("<td>" . $row["Label"]."</td>");
                    echo ("<td>" . $row["Address"]."</td>");
                    echo ("<td>" . $row["Type"]."</td>");
                    echo ("<td>" . $row["DisplayNumber"]."</td>");
                    echo ("<td>" . $row["Wiki"]."</td>");
                    echo "</tr>";
            }           

    } else {
        echo "No results founds";
    }

?>

<?php
    $external = getExternalNetworkTable();
    if ($external->num_rows > 0){


            //echo " <b>EXTERNAL</b>";      
            echo "<table cellspacing=\"0\">";
            echo "<tr>";
            echo " <th><b>Device</b></th>"; 
            echo " <th><b>Label</b></th>";
            echo " <th><b>Address</b></th>";
            echo " <th><b>Type</b></th>";
            echo " <th><b>DisplayNumber</b></th>";
            echo " <th><b>Wiki</b></th>";
            echo "</tr>";
            while ($row = $external->fetch_assoc()){
                    echo "<tr>";
                    echo ("<td>" . $row["Device"] ."</td>");
                    echo ("<td>" . $row["Label"]."</td>");
                    echo ("<td>" . $row["Address"]."</td>");
                    echo ("<td>" . $row["Type"]."</td>");
                    echo ("<td>" . $row["DisplayNumber"]."</td>");
                    echo ("<td>" . $row["Wiki"]."</td>");
                    echo "</tr>";

            }               

    } else {
        echo "No results founds";
    }
$conn->close();
?>  

EDIT: Needed to add:

echo "</table>";

New code:

<?php
    $internal = getNovatoInternalNetworkTable();
    if ($internal->num_rows > 0){


            echo " <b>INTERNAL</b>";
            echo "<table cellspacing=\"0\">";
            echo "<tr>";
            echo " <th><b>Device</b></th>"; 
            echo " <th><b>Label</b></th>";
            echo " <th><b>Address</b></th>";
            echo " <th><b>Type</b></th>";
            echo " <th><b>DisplayNumber</b></th>";
            echo " <th><b>Wiki</b></th>";
            echo "</tr>";
            while ($row = $internal->fetch_assoc()){
                    echo "<tr>";
                    echo ("<td>" . $row["Device"] ."</td>");
                    echo ("<td>" . $row["Label"]."</td>");
                    echo ("<td>" . $row["Address"]."</td>");
                    echo ("<td>" . $row["Type"]."</td>");
                    echo ("<td>" . $row["DisplayNumber"]."</td>");
                    echo ("<td>" . $row["Wiki"]."</td>");
                    echo "</tr>";

            }
                echo "</table>";

    } else {
        echo "No results founds";
    }

?>

<?php
    $external = getNovatoExternalNetworkTable();
    if ($external->num_rows > 0){


            echo " <b>EXTERNAL</b>";        
            echo "<table cellspacing=\"0\">";
            echo "<tr>";
            echo " <th><b>Device</b></th>"; 
            echo " <th><b>Label</b></th>";
            echo " <th><b>Address</b></th>";
            echo " <th><b>Type</b></th>";
            echo " <th><b>DisplayNumber</b></th>";
            echo " <th><b>Wiki</b></th>";
            echo "</tr>";
            while ($row = $external->fetch_assoc()){
                    echo "<tr>";
                    echo ("<td>" . $row["Device"] ."</td>");
                    echo ("<td>" . $row["Label"]."</td>");
                    echo ("<td>" . $row["Address"]."</td>");
                    echo ("<td>" . $row["Type"]."</td>");
                    echo ("<td>" . $row["DisplayNumber"]."</td>");
                    echo ("<td>" . $row["Wiki"]."</td>");
                    echo "</tr>";

            }
                echo "</table>";

    } else {
        echo "No results founds";
    }
$conn->close();
?>  
2
  • 5
    </table> is missing, this could be the problem. Commented Feb 28, 2018 at 17:16
  • You just made my day. Thank you so much. Commented Feb 28, 2018 at 17:20

1 Answer 1

1

You're missing </table> in both display of tables.

Therefore your table will be merge in each other.

    echo '</table>';

Before both of your } else { should do the trick

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

1 Comment

Yep. This is literally exactly what I just did once jonas3344 mentioned it. Thank you for the response.

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.