phppup Posted June 6, 2012 Share Posted June 6, 2012 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2012 Share Posted June 6, 2012 Remove all the - echo "<br />"; statements that are within the <table></table>. Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/#findComment-1351637 Share on other sites More sharing options...
phppup Posted June 6, 2012 Author Share Posted June 6, 2012 Sounds like that should do it, huh? Thanks for the solution. It seems sensible. I guess the PHP digests the <BR>s first, and then after they've been regergitated, it spits out the table that I wanted. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/#findComment-1351642 Share on other sites More sharing options...
Jessica Posted June 6, 2012 Share Posted June 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/#findComment-1351645 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2012 Share Posted June 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/#findComment-1351646 Share on other sites More sharing options...
phppup Posted June 6, 2012 Author Share Posted June 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263758-html-within-php/#findComment-1351663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.