Jump to content

Output format question...


stuart.cole

Recommended Posts

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]
Link to comment
Share on other sites

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 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;
}
?>[/code]

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.