Jump to content

is the a JS to read string from Mysql..etc


cool disel

Recommended Posts

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 ???

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

 

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  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.