PHP和JQuery实时定价。

I have a PHP loop, it loops through rows in the database and then list all cars.

$getcars = $carstring;
while($searchcars = mysql_fetch_array($getcars)) {

So I end up with this line numerous times:

<div id="price_<?php echo $carid; ?>">&euro;<?php echo number_format($bookingprice, 2); ?></div>

So everyone has a unique ID. All goo so far:

$bookingprice

Is a variable calculated by a PHP include file, and is a basic quote for a car.

The user can then add extras, and whilst doing this, I want to live update the price.

So I writ some JQuery:

        var price = "<?php echo $finalprice; ?>";
        alert(price);
        var numberofboostseat = $(this).val();
        alert(numberofboostseat);
        var numofdays = "<?php echo $length->days; ?>";
        alert(numofdays);
        var boostcost = Number(3) * Number(numofdays);
        var boosttotal = Number(numberofboostseat) * Number(boostcost);
        var newprice = Number(price) + Number(boosttotal);
        $('#price_<?php echo $carid; ?>').html(newprice);

My problem is that the script is not within the loop, so it doesn't know which price to update. If I make them all the same class, it updates all prices of every car on page, this isn't the desired result, I just want to update a certain price field, but I am struggling to figure out how to tell the JQuery which.

Any suggestions?

you can use the php script to print the html contents like

$cras = '';

while($searchcars = mysql_fetch_array($getcars)) {
    $cars .= '<div id=' . searchcars['id'] . '>&euro; ' . number_format(searchcars['bookingprice'], 2); . '</div>';
}

<div class="price">
<?php echo $cars; ?>
</div>