$query = "SELECT item, description, price, imageData, status, username, item_id FROM items"; 
	 
$result = mysql_query($query) or die(mysql_error());

$z=0;
while($row = mysql_fetch_array($result))
	{
	
	//echo other columns here//

	echo "<td><div id=status$z></div></td>";

<script type=text/javascript>
    function updatestatus(itemnum) {

    var url="updatestatus.php?auc=<?php echo $row['item_id']; ?>";

    jQuery('#status' + itemnum).load(url);  
	  
    }

    setInterval("updatestatus(<? echo $z?>)", 1000);
	
</script>
 <?   
    $z++;
	
}
?>

So basically I'm trying to get Jquery to update the status of each auction once every second. However, the statuses for each row are all the same which is not right. It appears that all the rows are populated with the same status as the last row.

Here's the code for updatestatus.php

<? 
session_start();
require_once("connect.php");

$id = $_GET['auc'];
$getstatus= mysql_query("SELECT status FROM items WHERE item_id = '$id'  ");
$row = mysql_fetch_array($getstatus);

	echo"$row[status]";

?>

Please let me know what I've done wrong.

Member Avatar for diafol

You're producing a vast amount of js with the first script. You need to just provide a general routine. You'll end up running hundreds of routines. Why not produce a script to make a general retrieval every few seconds?
I have to say - every second, may be a bit much - depending on the amount of data you're drawing down. If you get a hundred users on your site at the same time, the load on your DB will be HEAVY.

1. Main php page - include the updatestatus.php file to give the opening set of data.
2. Your interval js will already be placed in document.ready(...) so it starts running as soon as the page has loaded. It just calls ther same data from updatestatus.php and updates that part of the page.

<script>
  ...
   function updatestatus(){
      jQuery('#auctions').load('inc/updatestatus.php');
   }

   setInterval("updatestatus()", 5000);
  ...
</script>
...

<div id="auctions">
  include('inc/updatestatus.php');
</div>

Not tested

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.