homepage Welcome to WebmasterWorld Guest from 54.227.62.141
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Formatting HTML in PHP
Amy Ra Ra Ra




msg:4481922
 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




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

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




msg:4482281
 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




msg:4482283
 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




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

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




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

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

cffrost2




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved