stuart.cole Posted October 12, 2006 Share Posted October 12, 2006 Hi again,I have an issue, and although I see quite a bit of information I think should help, it just doesn;t seem to make sense - hence posting here...I have set a form up to add news to a database - works. The data when entered even has the physical line breaks and formatting of the data being pasted into it...Retreiving the information works, showing it works - formatting it is doing my head in...Is there a way to call the info with the formatting as it was when added to the database? I'm using an echo request as shown below, and have tried adding nl2br but with no joy ... any idea's?[code]<table width="640px" class="style10"><td><? $Newsid = $_GET['Newsid'];$query = "SELECT * FROM News WHERE Newsid='" . $Newsid . "'";$result = mysql_query($query) or die('Query failed: ' . mysql_error());while($row = mysql_fetch_array($result, MYSQL_ASSOC)){echo "<br><br><br><br>" . $row['Date'] . "<br><br>" . $row['Heading'] . "";echo "<br><br>" . $row['Subhead'] . "<br><br>" . $row['Main'] . "<p></p><p></p>";}?></td></table>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23749-output-format-question/ Share on other sites More sharing options...
HuggieBear Posted October 12, 2006 Share Posted October 12, 2006 Please put [b][[/b][b]code][/b] ... [b][[/b][b]/code][/b] tags around your code to make it more readable.As for your request, try this:[code]<?php// Get the value from the URL$Newsid = $_GET['Newsid'];// Construct and execute the query$query = "SELECT * FROM News WHERE Newsid = '$Newsid'";$result = mysql_query($query) or die('Query failed: ' . mysql_error());// Loop through the results creating a table for each rowwhile($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $main = nl2br($row['Main']); // Change the "\n" to <br> // Echo the code echo <<<HTML<table width="640px" class="style10"> <tr> <td>{$row['Date']}</td> </tr> <tr> <td>{$row['Heading']}</td> </tr> <tr> <td>{$row['Subhead']}</td> </tr> <tr> <td>{$main}</td> </tr></table><br /><br />HTML;}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23749-output-format-question/#findComment-107860 Share on other sites More sharing options...
Daniel0 Posted October 12, 2006 Share Posted October 12, 2006 This is off-topic, but well...HuggieBear: Instead of [nobbc][b][[/b][b]code][/b] ... [b][[/b][b]/code][/b][/nobbc] you can just type: [nobbc][nobbc][code] ... [/code][/nobbc][/nobbc] ;) Quote Link to comment https://forums.phpfreaks.com/topic/23749-output-format-question/#findComment-107896 Share on other sites More sharing options...
HuggieBear Posted October 12, 2006 Share Posted October 12, 2006 Thanks Daniel0That will speed things up for me :)RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23749-output-format-question/#findComment-107898 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.