Updating without reloading the page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Updating without reloading the page

Post by Covenant »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Okay I'm a bit new to PHP.   

Let's say the variable 'calories' is currently 450.

Code: Select all

<?php
 if($diet == "yes")
 {
  mysql_query("UPDATE mcdonalds set calories=calories-50 where id='1'");
  $currentcal=mysql_fetch_array(mysql_query("SELECT calories from mcdonalds where id='1'"));
 echo "Now it's only <b>$currentcal[calories]</b> calories!";
 exit;
 }
 print "<a href=?diet=yes>Diet!</a>";
 ?>
How would you get it so that the calories is updated on that page? So that it says "Now it's only 400 calories!" WITHOUT RELOADING THE PAGE? Is that not possible?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

You will have to look into AJAX. Do a search for it, we've discussed it before.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hidden iframe and/or xmlhttp/ajax are the only real options.. but it is suggested to just refresh the page..
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

dreamline wrote:Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)
Newer webbrowsers have been supporting it for years. It's just that few websites actually use AJAX. It's pretty damn powerful at any rate.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

dreamline wrote:Yea, i recently heard of AJAX, however it's still in a very early state, so i think in about 2 years it has been perfected and integrated in the whole web scene... :)
Just the term AJAX used to describe the technology is new...and maybe the XMLHttp technology...

I've used techniques such as hidden IFRAMES for a long time now...

Prior to AJAX this was more commonly refered to as Javascript RPC (remote procedure calls)

This is cool stuff...but there are inherent problems...for instance...if your entire app is powered by Ajax, you loose you browsers back button functionality...a page update using AJAX doesn't register anything with the browser cache...

Most users (myself included) are very comfortable using back/forward buttons while using web apps :)

Just a reminder :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a few browsers do actually cache the results of requests made via AJAX...
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

feyd wrote:a few browsers do actually cache the results of requests made via AJAX...
Really?

Cool...which ones?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if memory serves me, IE6 and Gecko 1.4+ based browsers do.. but don't quote me on that ;)
Post Reply