Need help using jQuery to run a php file and retrieve the data

Need help using jQuery to run a php file and retrieve the data

Hello,

I'm struggling to write a jquery script which will run a php file to and retrieve the results. The php file will produce the results in xml format and the jquery script needs to retrieve them and then show them on the current page.

Basically I want to retrieve data from a database and then update the current page, the script needs to run the php file every 15 seconds and automatically update the current page. The data needs to be taken from the xml and update elements on the current page. The problem I am having is I need to update multiple php variables which are all called the same things.

Below is a example of the code on the first page, it first retrieves the data from the database and turns it into a number of progress bars and shows however many progress bars are needed depending on other variables which are worked out before on the page.




  1. while($rows=mysql_fetch_array($result)){
  2. $id=$rows['id'];
  3. $prog1=$rows['prog1'];
  4. $prog2=$rows['prog2'];
  5. $name1=$rows['name1'];
  6. $name2=$rows['name2'];
  7. $progress1=($prog1/20)*100;
  8. $progress2=($prog2/20)*100;
  9. ?>

  10. <!---------- progress bars ----------->
  11. <div id="<?php echo $id."left"; ?>"
  12. <div id="progress" style="width:<?php echo $progress1; ?>%">
  13. <?php echo $name1; ?></div>
  14. </div>

  15. <div id="<?php echo $id."right"; ?>"
  16. <div id="progress" style="width:<?php echo $progress2; ?>%">
  17. <?php echo $name2; ?></div>
  18. </div>
  19. <!------------------------------------>

  20. <?php
  21. }

I would then like these progress bars to be updated every 15 seconds, but I have no idea how to do this, would anybody be able to help please.

P.s the php file that will be run every 15 seconds to produce the xml, I guess will look something like this:

  1. while($rows=mysql_fetch_array($result)){
  2. $id=$rows['id'];
  3. $prog1=$rows['prog1'];
  4. $prog2=$rows['prog2'];
  5. $name1=$rows['name1'];
  6. $name2=$rows['name2'];
  7. $progress1=($prog1/20)*100;
  8. $progress2=($prog2/20)*100;
  9. ?>
  10. <progress> 
  11. <id><?php echo $id; ?></id> 
  12. <name1><?php echo $name1; ?></name1> 
  13. <name2><?php echo $name2; ?></name2> 
  14. <progress1><?php echo $progress1; ?></progress1>
  15. <progress2><?php echo $progress2; ?></progress2>
  16. </progress>
  17. <?php
  18. }

So any help writing the script would be much appreciated, im a total beginner with jQuery and could do with as much help as possible, thanks.