Forum Moderators: coopster

Message Too Old, No Replies

Passing DB fields into an array and using JavaScript to "rotate"

         

jjhenry78

6:48 pm on Feb 20, 2008 (gmt 0)

10+ Year Member



I am setting up a site where the client would like to update current information and have that automatically rotate on their homepage through all the contents of that database on a set interval. I have set up the Java file to pull the info off of my .php page, however, i can't figure out how to set it to pull the next record after the time interval has elapsed. It'll pull the first record, but not pass the second and so on. I am sure i have to set up an array to get all the info from the database and pass the ID's to the java file. My question is on how to complete that. Do i put the array in the java file or in the php file? Thanks in advance for any help.

Josh

[edited by: eelixduppy at 7:32 pm (utc) on Feb. 20, 2008]
[edit reason] no signatures, please [/edit]

phparion

6:11 am on Feb 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to the WebmasterWorld!

there could be two methods to accomplish your task as described below,

1 - make a php page which reads the id and fetches related record and print it; call your javascript function in the intervals and send id to the php page, read back the output and display it on the page assigning values to DIV etc...

2 - make a php page that reads all the records and print it using a 'splitter' symbol e.g pipe key (¦) e.g

echo "$rec1" . "¦" . $rec2 . "¦" .. and so on

then use split() function of javascript, similar to explode of php, and make an array of the php page output... then in intervals reads the next array value by simply calling the javascript function with a parameter in which you sends it the current array index and then increment by 1 to pick the next element

jjhenry78

4:26 pm on Feb 25, 2008 (gmt 0)

10+ Year Member



Could you help me with an example of what the PHP code would look like that fetches the id's and then puts them into the java array for display?

Josh

coopster

12:29 am on Feb 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, jjhenry78.

How about giving it your best attempt [webmasterworld.com] first and we go from there?

phparion

11:40 am on Feb 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



PHP:

BEGIN
DEFINE a variable A with NULL
QUERY DATABASE TO GET RESOURCE(OPT: any conditions)
START LOOP
concatenate using PIPE KEY (¦) all values in A
END LOOP
DISPLAY A
END

When you display the information on php page, your javascript STATE 4 event is called automatically, if not getting it please start ajax from start, then do something like following

JAVASCRIPT:

var ress
function handleHttpResponse() {
if (http.readyState == 4) {
if(http.status==200) {
results=http.responseText;

ress = results.split('¦')
alert(results)

ress now has the values in the form of an array