Jump to content

HTML within PHP


phppup

Recommended Posts

I want to print out the findings of my query in a table format.  Yet when I include the <table> tag the information drops to a position half way down the browser page.  Is there a PHP reason for this?

 

<?php 

 

**connection info***

 

 

 

echo "TITLE HERE";

 

echo "<br>";

 

$queryC = "SELECT * FROM MYTABLE WHERE pants>0  ORDER BY pants,id ASC";

 

$resultC = mysql_query($queryC) or die(mysql_error());

 

 

 

echo "<table border='1'>";  //the TABLE TAG is FORCING the display to the BOTTOM of the PAGE

echo "<tr> <th>Order</th> <th>Customer</th> <th>Amount</th> </tr>";

 

 

 

// Print out result

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

 

// use the DOT to CONNECT html in QUOTES and PHP-terms

 

echo "<br />";

echo "<tr><td>";

echo  "#" . $row['id'] ;

echo "</td><td>";

echo $row['customer']; 

echo "</td><td>";

echo $row['pants'] ;

echo "</td></tr>";

 

echo "<br />";

 

}

 

echo "</table>";

 

         

mysql_close();

 

?>

 

 

Link to comment
Share on other sites

No, it has nothing to do with PHP. You're putting a <br> in an invalid location within a table. Different browsers may interpret this differently, but it looks like the one you used puts the <br> before the table.

What you wrote is basically this in plain HTML:

<table>
    <tr>
        <br>
        <td>Text</td>
    </tr>
    <br>
</table>

 

What were you trying to do?

You don't need <br> between your rows, they automatically are new rows by virtue of the <tr> (table row) tag.

Link to comment
Share on other sites

Edit: Basically the same as what jesirose states above ^^^

 

Php doesn't have anything to do with this. Php simply outputs what you tell it to do. It's up to the browser to render the html that it is sent. The <br /> tags are inside the table tags but outside of any <tr></tr> tags.

Link to comment
Share on other sites

OKAY!  I got it.  Thanks again.

 

The <BR> was there because the info was originally printed out within a sentence.

(ie: Order number '$id' for '$customer name' contains '$quantity' of this item.)

 

I needed the HTML breaks to avoid a running sentence.

 

When I switched the data into a table, the BR's go overlooked.

 

Thanks for all the assistance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.