Jacbey Posted February 18, 2013 Share Posted February 18, 2013 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 https://forums.phpfreaks.com/topic/274614-ajax-refresh-item-list-qty/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.