i have a problem with this code, in INSERT only insert the first item_price in every insert, in example i have three differents item_price, thanks for you help sorry for bad english
html part in table:
<table>
<tr id="shop1">
<td>1</td> <!-- item_id -->
<td><input type="text" value="33" name="price"></td> <!-- item_price -->
</tr>
<tr id="shop2">
<td>2</td> <!-- item_id -->
<td><input type="text" value="11" name="price"></td> <!-- item_price -->
</tr>
<tr id="shop3">
<td>3</td> <!-- item_id -->
<td><input type="text" value="65" name="price"></td> <!-- item_price -->
</tr>
</table>
<button id="checkoutinventory" class="btn-danger"></button>
javascript part:
$(document).on("click","button#checkoutinventory, a[href$='checkoutinventory']",function()
{
var items = "";
var price = "";
$("tr[id^=shop] button.btn-danger").each(function()
{
items += $(this).parents("tr").attr("id").replace(/\D/g,'')+",";
price += $(this).parents("tr").find('input[name="price"]').val().replace(/\D/g,'')+","; //this code send price in this format: 1,2,3,etc
});
if (!items)
return displayResponse("ERROR","an error ocurred try again.");
var settings = {};
settings['action'] = "checkoutinventory";
settings['items'] = items;
settings['price'] = price;
$.get("includes/process.php", settings, function(data)
{
processResponse(data);
});
return false;
});
process.php part:
if ($_GET['action'] == "checkoutinventory")
{
if (!@$character)
exit("REFRESH");
if (!$VALIDATE->blank(@$_GET['items']))
exit();
$items = explode(",", rtrim($_GET['items'],",")); //Here obtain item_id in this format: id_1,id_2,id_3,etc
$price = $_GET['price']; //Here obtain item_price in this format: price1,price2,price3,etc
$isonline = $SERVER->select($query['characterIsonline'],array($COOKIE->get("character")));
if(!$isonline)
{
$itemData = $SERVER->select("SELECT * FROM `items` WHERE `object_id` IN (".implode(",",$items).");",array()); //Here obtain perfectly information for insert later in foreach
} else {
exit("RESPONSE^ERROR^Your character <b>".$character['char_name']."</b> is online disconnect please and try again..");
}
if($itemData) {
foreach($itemData as $itemlist)
{
$selling = $SERVER->insert("INSERT INTO `shop_items` (`itemId`,`itemAmount`,`itemPrice`,`itemEnchant`,`vendedor`,`object_id`) VALUES (?,?,?,?,?,?);",array($itemlist['item_id'],$itemlist['count'],$_GET['price'],$itemlist['enchant_level'],$character['char_name'],$itemlist['object_id']));
}
}
if (count($items) != count($itemData))
exit("RESPONSE^ERROR^One of the items is no longer available for sale.");
if($selling) {
exit("RESPONSE^SUCCESS^Congrats <b>".$character['char_name']."</b>, you sell ".count($items)." item(s)!");
}
exit("RESPONSE^ERROR^Unexpected error occured.");
}