Current location: Hot Scripts Forums » Programming Languages » PHP » help plz: format retrieved Mysql data in HTML with PHP


help plz: format retrieved Mysql data in HTML with PHP

Reply
  #1 (permalink)  
Old 10-19-03, 05:01 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
help plz: format retrieved Mysql data in HTML with PHP

I am looking for ways to format information from a mysql database into HTML. For instance if someone enters the following info in text box that will be inserted into a mysql table how do i retrieve it in a nice, formatted <li>fashion</li>.

The following goes into database from a textarea:

feature 1
feature 2
feature 3
feature 4
feature 5
feature 6

then it is retrieved with PHP and desired to be in the <LI> format like this:

<UL>
<LI>feature 1</LI>
<LI>feature 2</LI>
<LI>feature 3</LI>
<LI>feature 4</LI>
<LI>feature 5</LI>
<LI>feature 6</LI>
</UL>

How do I read this sort of data that is all in one "TEXT" entry in a database into HTML?
- thank you very much - Paul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-19-03, 06:59 AM
siavash siavash is offline
New Member
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
you must use some code like this:

<html>
<head><title>List</title></head>
<body>
<form action="<?php echo $PHP_SELF ?>" method="post">
List:<textarea name='text' cols="50" rows="10"></textarea>
<input type="submit" value="Submit!" />
<input type="hidden" name="submited" value="true" />
</form>

<?php
if($submited){
$tmp=explode("\n",$text);
$list='<UL>';
for($i=0;$i<count($tmp);$i++)
$list.="<LI>".$tmp[$i]."</LI>";
$list.='</UL>';
echo $list;
}
?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-19-03, 09:03 PM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
So you basically rely on detecting the "\n" at each line of text, turn all of the lines into array elements and then count the elements and run through a loop, echo'ing each element in the <LI> formatting. That makes sense to me.

I was originally thinking along the lines of ereg_replace each "\r" with "</LI><LI>" but I like your way better.

1 - So, is that the basis of formatting all these types of database entries... explode on the "\n"?
2 - Also, what type of column should these go into the mysql database as? TEXT or BLOB?

THanks a bunch for the advice - Paul
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
one-page form/catalog in php, data fed in with .csv file? domaky PHP 2 10-25-03 10:32 AM
Pulling data from MySQl Database w/ PHP? dayzeday PHP 6 10-07-03 08:01 AM
date format for mysql runya PHP 3 07-28-03 01:56 AM
Free PHP, Perl and possible mySQL hosting! toby General Advertisements 8 06-17-03 02:04 AM


All times are GMT -5. The time now is 01:23 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.