Jump to content

AJAX Refresh Item List Qty


Jacbey

Recommended Posts

Hi guys,

 

I'm a real newbie to AJAX and I've dived straight in at the deep end. I have a list of items that I am pulling from a database with a quantity displayed next to them. The quantity is constantly changing and I want this to be automatically updated on the page without having to refresh it.

 

This is the PHP for the list:

 

while($sweet_counter < $sweet_numbers) {




if($cellcnt == 1){
 $shelfpart = "shelf-two.png";
}
elseif($cellcnt == 2){
 $shelfpart = "shelf-three.png";
}
elseif($cellcnt == 3){
 $shelfpart = "shelf-three.png";
}
elseif($cellcnt == 4){
 $shelfpart = "shelf-four.png";
}


$itemname = mysql_result($sweet_result,$sweet_counter,'item_name');
$item_stock = mysql_result($sweet_result,$sweet_counter,'item_stock');
 $item_id = mysql_result($sweet_result,$sweet_counter,'item_id');
 $item_cost = mysql_result($sweet_result,$sweet_counter,'item_cost');
$new_itemname = wordwrap($itemname, 10, "<br />\n");


$sweetslist[] = '
 <td width="242" height="194" style="background-image: url(\'images/shelf/' . $shelfpart . '\'); background-repeat: no-repeat">
	 <div id="item_wrapper">
	 <div id="item_name">
	 ' . $new_itemname . '
	 <br />
	 <br />
	 ' . $item_cost . 'p
	 </div>
	 <div id="item_stock">
	 <span class="counter stock" id="counter stock">
	 <div id="item_id_stock_' . $item_id . '">
		 ' . $item_stock . '
	 </div>
	 </span>
	 </div>
	 </div>
 </td>
 ';


$newnumber_to_count = $sweet_numbers - 1;


if($sweet_counter == $newnumber_to_count){
 $sweetslist[] = '<td width="35" height="194" style="background-image: url(\'images/shelf/shelf-five.png\'); background-repeat: no-repeat">
  
 </td></tr>';
}
else if ($cellcnt == 4) {
 $sweetslist[] = '<td width="35" height="194" style="background-image: url(\'images/shelf/shelf-five.png\'); background-repeat: no-repeat">
  
 </td></tr><tr><td width="35" height="194" style="background-image: url(\'images/shelf/shelf-one.png\'); background-repeat: no-repeat">   </td>';
$cellcnt = 0;
}


$cellcnt++;
$sweet_counter++;
}

 

I have already made a few AJAX scripts work fine but this is absolutely confusing me as to how I could do it to update each quantity on the page when it is changed. Any help would be greatly appreciated.

 

Many thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.