Jump to content

Updating Content (In a single webpage)

- - - - -

  • Please log in to reply
5 replies to this topic

#1
pally98

pally98

    Newbie

  • Members
  • Pip
  • 8 posts
Hey thanks for checking out my thread

Asking for the best way to program the following type of example



a small box in the top of my site.. and a big box in the middle of my website

now I want these areas updating every few minutes pulling new content from my database (mysql)(users will consistently be adding new data)

Also if the user clicks the small box then I want that type of content to swap places with the big box..


I would prefer this all be instant and not require page refreshing (like ajax)



my concerns are how to do this most effectively?

in order to get new information from the mysql database requires a complex algorithm I'd rather pull with php


maybe its possible to have ajax call a php function and order the received input?
or is there a better programming language I could program my site with for its application like structure?




Thank you for you time, appreciate the help,
Ryan

#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Well, you will most likely need ajax.
But you cannot directly call a php function via ajax.
You can however call a webpage that will display the last result, and simply display them.
Easiest way would be to have either an id or a datetime that you send with your ajax request, and php will load the data with a higher value.

An other way would be to use the sleep function in php.
This technics have a name, but I don't remember it.
In a nut shell, you query your data, with php, and insted of ending the script you enter in a infinite loop with a sleep in it.
So insted of the webbrowser trying to get new data, php will send the new data.
Of course with this data, you will still need some ajax, since a php script cannot load forever, you have a timeout.

#3
pally98

pally98

    Newbie

  • Members
  • Pip
  • 8 posts
Hey thanks for the reply..

I'm open to any method of retrieving the data really

I just want to update the data every few minute.. but since the data I am grabbing is not a static file that static text saying "blah blah" like most ajax request are made for

I want it to request new data by doing an algorithm that says.. find data similar to xyz, return it, and display it here



understanding how facebook updates its "news feed" with "recent stories" may unlock some of my questions as well


and on a different note I was thinking maybe JSP might be easier for this kind of stuff I want to do.. I can program in java.. but never messed with JSP.. just heard of.. anyone have insight into this?


thanks again

#4
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Well, php or jsp will be the same.
ajax isn't made for static file, it's only to contact the server.
So if the page you contact is a php file, the result will change

In php or jsp, you will have to do the exact same thing
Receiving the call
Look for a variable for a indication for the last time the script ask for update
Fetch data from mysql
And display it. Either as html, xml, json or other format

#5
pally98

pally98

    Newbie

  • Members
  • Pip
  • 8 posts
sorry that was just my lack of experience with JSP and ASP

so I just need to figure out how to have a php script change a few variables.. and tell ajax to read those php variable

everything else after that I already know how to do... I just am not sure if it is that simple.. or how to have ajax and php communicate


I guess like you said.. have php script write some data to a webpage that has a unique userId
then have ajax request the data from that page

I suppose that works if I cannot have ajax and php share a common variable



thanks again

#6
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
When you make a ajax call, add a variable to the url like so www.test.com/index.php?id=4
When index.php will be executed he will have the variable $_GET['id'] set to 4




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users