cool disel Posted March 29, 2009 Share Posted March 29, 2009 hi i'm new to PHP and i was wondering if there is a JS that would read a string from mysql and put it in an array then do a for loop to check for "," commas and place a <br/> so i can create a new lines.. so for example: i'd write a text like this "i'm a new to php,and i love it" so after the JS process it it would look like this: " i'm new to php and i love it " i read about nl2br but i had no i dea how to u it ??? Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/ Share on other sites More sharing options...
RichardRotterdam Posted March 29, 2009 Share Posted March 29, 2009 i was wondering if there is a JS that would read a string from mysql You could if you have serverside JS. But usually js is used clientside. Why would you want this with js ? Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796186 Share on other sites More sharing options...
cool disel Posted March 29, 2009 Author Share Posted March 29, 2009 i was wondering if there is a JS that would read a string from mysql You could if you have serverside JS. But usually js is used clientside. Why would you want this with js ? is there other way to do it? in my head i think its a good idea bcoz when the data is fatched from the DB the JS will format it inside the web page.. i don't if its good or not or if there r better ways to do it? Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796191 Share on other sites More sharing options...
RichardRotterdam Posted March 29, 2009 Share Posted March 29, 2009 when the data is fatched from the DB If you have a server that runs PHP use PHP to fetch data from the database is there other way to do it? Any serverside language you have on your server will do. JS will format it inside the web page.. Is there any reason you want js to output data to the webpage instead of using regular html? Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796193 Share on other sites More sharing options...
cool disel Posted March 29, 2009 Author Share Posted March 29, 2009 when the data is fatched from the DB If you have a server that runs PHP use PHP to fetch data from the database is there other way to do it? Any serverside language you have on your server will do. JS will format it inside the web page.. Is there any reason you want js to output data to the webpage instead of using regular html? hi first thank u for ur response:) second i think there's a miss understanding between us.. the PHP script will fetch the data from the DB and bcoz when u store multiple lines the DB will store as a single line so when u retrive it it will be in single line and not in the original format.. so my idea is to ask the user to seperat the lines with comma "," so when the data is fetched from the server, the JS on the Client side or the server will reconise the commas "," and interperate it as a<br/> so the data will be formated the same way the user inserted it the idea is i'm planning to create a food reciepe web site for a friend of mine and he can insert the reciepes using an admin page then the users can view his reciepe Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796201 Share on other sites More sharing options...
RichardRotterdam Posted March 29, 2009 Share Posted March 29, 2009 the PHP script will fetch the data from the DB and bcoz when u store multiple lines the DB will store as a single line so when u retrive it it will be in single line and not in the original format.. Why not simply store html in a db field using a RTE(Rich Text Editor) such as tinyMCE instead of parsing , to create new lines? tinymce fckeditor Also if you really want the user to create new lines with a comma you could simply use str_replace to replace all the , with a <br /> tag. I don't really see the point of JS here Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796205 Share on other sites More sharing options...
cool disel Posted March 29, 2009 Author Share Posted March 29, 2009 the PHP script will fetch the data from the DB and bcoz when u store multiple lines the DB will store as a single line so when u retrive it it will be in single line and not in the original format.. Why not simply store html in a db field using a RTE(Rich Text Editor) such as tinyMCE instead of parsing , to create new lines? tinymce fckeditor Also if you really want the user to create new lines with a comma you could simply use str_replace to replace all the , with a <br /> tag. I don't really see the point of JS here thank you very much u just maid my life esier Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796212 Share on other sites More sharing options...
RichardRotterdam Posted March 29, 2009 Share Posted March 29, 2009 You're welcome. Out of curiosity which option did you choose? Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796213 Share on other sites More sharing options...
cool disel Posted March 29, 2009 Author Share Posted March 29, 2009 You're welcome. Out of curiosity which option did you choose? i thinking of going with the RTE its much easier that way now doing research b4 implemnting it Quote Link to comment https://forums.phpfreaks.com/topic/151594-is-the-a-js-to-read-string-from-mysqletc/#findComment-796304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.