Jump to content


Photo

Output format question...


  • Please log in to reply
3 replies to this topic

#1 stuart.cole

stuart.cole
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 11:56 AM

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?



<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>


#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 October 2006 - 12:10 PM

Please put [code] ... [/code] tags around your code to make it more readable.

As for your request, try this:

<?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 row
while($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;
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 12 October 2006 - 01:28 PM

This is off-topic, but well...

HuggieBear: Instead of [b][[/b][b]code][/b] ... [b][[/b][b]/code][/b] you can just type: [nobbc][code] ... [/code][/nobbc] ;)

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 October 2006 - 01:31 PM

Thanks Daniel0

That will speed things up for me :)

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users