could you please help me with the following:
At the moment i am stuck with a while loop using PHP and looping through a database query which give 5 results and in that while loop i created for each result of the loop a window with html/css which shows products and inside that window it contains also + and - buttons to add or substract products and for that i used a JavaScript function.
So what i get with that while loop is this:
<?php
while ($row = mysql_fetch_assoc($resultaat)) {
echo "
<div class='row tussenruimte'>
</div>
<div class='flex-container product-container'>
<div class='flex-item product-c-1'>
<img src='../imgs/img5.jpg' id='img5-bezorgen'></img>
</div>
<div class='flex-item product-c-2'>
<div class='row titel-product-row'>
<div class='col-md-8'>
"
. $row['naam'] .
"
</div>
</div>
<div class='row omschrijving-product-row'>
<div class='col-md-12'>
"
. $row['omschrijving'] .
"
</div>
</div>
</div>
<div class='flex-item product-c-3'>
<div class='flex-container p-c-3-c'>
<div class='flex-item p-c-3-i'>
<form action='' method='GET'>
<div class='row product-toevoegen-rij'>
<div class='col-md-4 product-aantal-invullen'>
<div id='aantal'>0</div>
</div>
<div class='col-md-4 product-aantal-toevoegen'>
<button class='product-aantal-toevoegen-knop-css' onclick='increase(); return false;'>+</button>
</div>
<div class='col-md-4 product-aantal-aftrekken'>
<button class='product-aantal-aftrekken-knop-css' onclick='decrease(); return false;'>-</button>
</div>
</div>
<div class='row product-toevoegen-knop'>
<button class='toevoegen-knop-css' onclick=''>toevoegen aan winkelwagen</button>
</div>
<div class='row product-toevoegen-prijs'>
<div class='col-md-12 prijs-col'>
"
. $row['prijs'] .
"
</div>
</div>
</form>
</div>
</div>
</div>
</div>
";
}
?>
// And here is the JavaScript function:
<script>
var i=0;
function increase()
{
i++;
document.getElementById('aantal').innerHTML= +i;
}
function decrease()
{
i--;
document.getElementById('aantal').innerHTML= +i;
}
</script>
But the problem is that the JavaScript function doesn't respond with an unique product in the while loop.
If i have 5 products which are shown. Then the JavaScript function works only for 1 product.
Could someone help me out with how i could figure this out? I tried making the JavaScript function unique but i don't know how i should.
Thanks in advance!