Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Formatting HTML in PHP

     

Amy Ra Ra Ra

12:50 am on Aug 5, 2012 (gmt 0)



I am writing code to display in the browser the info that's been submitted into the comments database. The comments that users submit using my form should upon submission stretch out across the browers page but it doesn't, instead each word in the paragraph is on it's own line.

HERES THE PHP CODE:

<body>
<?php
$dbc = mysqli_connect ('dbhost', 'dbusername', 'dbpass', 'bdname')
or die('Error connecting to MySQL server.');

$query = "SELECT * FROM comments";
$data = mysqli_query($dbc, $query);

echo '<table>';
while ($row = mysqli_fetch_array($data)) {
echo '<tr><td><strong>Comments:</strong> ' . $row ['comments'] . '</td></tr>';
}
echo '</table>';

mysqli_close($dbc);
?>

</body>

rainborick

4:00 am on Aug 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is that you didn't add a 'width' attribute to the <table> tag that would tell the browser how you wanted the information to be displayed. Try:

echo('<table width="100%" cellpadding="4" cellspacing="0" border="0">');

Amy Ra Ra Ra

6:10 pm on Aug 6, 2012 (gmt 0)



That doesn't work and even when I've tried the following it still doesn't work:


while ($row = mysqli_fetch_array($data)) {
echo '<p><strong>Comments:</strong> ' . $row . '</p>'; ['comments'] . '</td></tr>';
}

Amy Ra Ra Ra

6:28 pm on Aug 6, 2012 (gmt 0)



Oh and I think that you might be wrong about the way to lay out that table. According to the following infor by jatar_k
[webmasterworld.com...] you're suppose to use slashes before the double quotes but only if you're using double quotes to define the echo statement, so it should be written as so, but still yet even with all of thi this info it didn't work:

echo "<table width=\"100%\" cellpadding=\"4\" cellspacing=\"0\"
border=\"0\">";

while ($row = mysqli_fetch_array($data)) {
echo '<tr><td><strong>Comments:</strong> ' . $row['comments'] . '</td></tr>';
}
echo "</table>";

lucy24

10:30 pm on Aug 6, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



echo "<table width=\"100%\" cellpadding=\"4\" cellspacing=\"0\"
border=\"0\">";

while ($row = mysqli_fetch_array($data)) {
echo '<tr><td><strong>Comments:</strong> ' . $row['comments'] . '</td></tr>';
}
echo "</table>";

Make up your mind, willya? ;) Either double quotes on the outside with escaped quotes for the literal quotation marks being echo'd, or double quotes on the outside and single quotes for the literal quotes being echo'd.

:: sitting on hands to avoid introducing wholly tangential CSS motif into discussion ::

Amy Ra Ra Ra

1:47 am on Aug 7, 2012 (gmt 0)



Ok but it still didn't fix my problem, but thanxs anyways.

cffrost2

12:06 pm on Aug 7, 2012 (gmt 0)

5+ Year Member



Amy. Be sure to re check the way it's being stored to the db in the first place. I don't see any reason here that each word would be each on a separate line unless each word is being store in a separate line in the db or the comments are formatted wrong. Also, view the page source of the outputted HTML and see what it looks like. Is there a <br /> tag after each word? Is there a </tr> tag after each word? That should help point you to the culprit creating your problem. Hope that helps.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month