Сообщение от j0hnik
|
не пойму про какой вы цикл
|
while (($cat = mysqli_fetch_assoc($products))){
$id=$cat['id'];
$order = mysqli_query($connection, "SELECT * FROM `order` WHERE `id`=1"); //// products
$zamowienie = mysqli_fetch_assoc($order);
if($zamowienie[$id]>0){
$x++;
$y=$x%2;
if($y==1){
$color='czemny';
}else{$color='szwetly';}
echo'<tr class="'.$color.'">
<td class="t_title">'.$cat['name'].'</td>
<td>'.$cat['characteristic'].'</td>
<td>
<form method="POST" action="" id="minus'.$id.'" style="float:right">
<input class="serle" name="test" value="'.$id.'">
<input onclick="minus()" id="result'.$id.'" type="submit" value=" – ">
</form>
<span style ="margin-left:3px" id="inc'.$id.'">'.$zamowienie[$id].'</span> шт.
<form method="POST" action="" id="plus'.$id.'" style="float:left">
<input class="serle" name="test" value="'.$id.'">
<input onclick="plus()" id="result'.$id.'" type="submit" value=" + ">
</form>
</td>
<td>'.$cat['price'].' р</td>
<td class="nie_maly"><span id="summ'.$id.'">'.$zamowienie[$id]*$cat['price'].'</span> р</td>
</tr>';
?>
<script type="text/javascript">
var id="<?=$id?>";
var plus_ = '#plus'+id;
var minus_ = '#minus'+id;
var result_ = 'result'+id;
$(function(){
$(plus_).submit(function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
type: "POST",
url: "plus.php",
data: data,
success: function(result_){
$(result_).html(result_);
}
});
});
});
$(function(){
$(minus_).submit(function(e){
e.preventDefault();
var data = $(this).serialize();
$.ajax({
type: "POST",
url: "minus.php",
data: data,
success: function(result_){
$(result_).html(result_);
}
});
});
});
</script>
<script>
var inc_ ='inc'+id;
var summ_ ='summ'+id;
var inc=<?=$zamowienie[$id]?>; // ilosc towaru
var kosz=<?=$cat['price']?>; // cena towaru
function minus() {
inc=inc-1;
if(inc>0){
inc=inc;
}
else{inc=0;}
document.getElementById(inc_).innerHTML = inc;
var sum=inc*kosz;
document.getElementById(summ_).innerHTML = sum;
}
function plus() {
inc=inc+1;
document.getElementById(inc_).innerHTML = inc;
var sum=inc*kosz;
document.getElementById(summ_).innerHTML = sum;
}
</script>
цикл while