Jump to content


Photo

AJAX Refresh Item List Qty


  • Please log in to reply
No replies to this topic

#1 Jacbey

Jacbey

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 17 February 2013 - 10:04 PM

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">
	 &nbsp;
	 </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">
	 &nbsp;
	 </td></tr><tr><td width="35" height="194" style="background-image: url(\'images/shelf/shelf-one.png\'); background-repeat: no-repeat"> &nbsp; </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!
The only thing you can learn from Dreamweaver is how not to build a website, and the only thing you can learn from jquery is how not to learn Javascript.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com