Page 1 of 1

Retrieveing info from MySql Database

Posted: Tue Jan 14, 2003 1:07 pm
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.

Posted: Tue Jan 14, 2003 1:16 pm
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 $

Wow my head really does hurt

Posted: Tue Jan 14, 2003 1:32 pm
by smoky989
Man My brain really does hurt. I was reading about that function last night and forgot. Thanks!