Retrieveing info from MySql Database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Retrieveing info from MySql Database

Post by smoky989 »

For anyone who looked at my code on my last post thanks. I'm gonna use a few arrays and functions to reduce the code and see what happeens than.

Now I have another question for you all. It seems simple enough but my head is killing me so I'm trying not to think right now. I have information enetered into a database seperated by commas. Now when I want to retrieve this I want their to be a <br> tag wherever a comma occurs. Any tips for me? Thanks in advance.
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

Code: Select all

<?php
#fetch the result of your query
$row = mysql_fetch_assoc($result);

#set the value of the my_text var to your text
$my_text = $row['my_text_field'];

#now replace all commas with <br />s
$my_text = str_replace(',', '<br />', $my_text);
?>
you can read the manual for the str_replace function for additional help.

Edit: added a missing $
smoky989
Forum Commoner
Posts: 41
Joined: Mon Sep 02, 2002 1:14 pm

Wow my head really does hurt

Post by smoky989 »

Man My brain really does hurt. I was reading about that function last night and forgot. Thanks!
Post Reply