Hi,
I have a page(page1) which dynamically displays the content of a mysql database column. The column takes input as text from a <textarea> field on another form on another page(page2).
The problem is when the result is diplayed in html on the first page(page2), it looses its initial formatting of pragraphs, spacing e.t.c. that was originally typed in the input page(page2). But I want the spacing and paragraghs to be displayed as well.
Any suggestions...
Thank you.
Formatting the result of SQL query in HTML
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Formatting the result of SQL query in HTML
Can you give us an example! I think I know what the problem could be.
Re: Formatting the result of SQL query in HTML
Thanks for the reply.
An example;
Supposing I have a page(index.php) that contains some information about my site. But i want the content(text) on the page to be loaded from a database column(db_pagecontent) of type text.
I also have another page (manager.php) where I have a <textarea> html field where I can view,edit or delete content and save it to (db_pagecontent).
When index.php load it queries my database and loads the text in db_pagecontent as html text.
sample code of index.php:
----------------------------------------------
<?php
include("connectx.php");
$query = "SELECT db_pagecontent FROM index";
$result= mysql_query($query,$cnx);
$rows = mysql_fetch_array($result);
?>
<html>
<body>
echo"$rows['db_pagecontent']";
</body>
</html>
---------------------------------------------------
Thank you.
An example;
Supposing I have a page(index.php) that contains some information about my site. But i want the content(text) on the page to be loaded from a database column(db_pagecontent) of type text.
I also have another page (manager.php) where I have a <textarea> html field where I can view,edit or delete content and save it to (db_pagecontent).
When index.php load it queries my database and loads the text in db_pagecontent as html text.
sample code of index.php:
----------------------------------------------
<?php
include("connectx.php");
$query = "SELECT db_pagecontent FROM index";
$result= mysql_query($query,$cnx);
$rows = mysql_fetch_array($result);
?>
<html>
<body>
echo"$rows['db_pagecontent']";
</body>
</html>
---------------------------------------------------
Thank you.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Formatting the result of SQL query in HTML
I was expecting to see what the error was, ie. text before and text after. So I can see the exact problem
I assume you are loosing the line breaks.
You will just need to do a replace all for all the '\r\n' to '<br>' (if xhtml standard) or '<br />' (if xhtml strick) before you display it to the screen and you will get the correct paragraph formating.
I assume you are loosing the line breaks.
You will just need to do a replace all for all the '\r\n' to '<br>' (if xhtml standard) or '<br />' (if xhtml strick) before you display it to the screen and you will get the correct paragraph formating.
Re: Formatting the result of SQL query in HTML
Thanks for that.
I wuld try it and get back to you.
NB This site has been having issues, sometimes I get a network error trying to load it, hence the late reply.
I wuld try it and get back to you.
NB This site has been having issues, sometimes I get a network error trying to load it, hence the late reply.
- Bill H
- DevNet Resident
- Posts: 1136
- Joined: Sat Jun 01, 2002 10:16 am
- Location: San Diego CA
- Contact:
Re: Formatting the result of SQL query in HTML
Check the nl2br() function.