I want to update the current bonus points for some customer and I'm running the following query:
UPDATE bp_booking SET `current_bonuspoints`=
(SELECT customers_bonus_points FROM customers WHERE customers_id='505')
WHERE` `customers_id`=505 AND date_altered=max(date_altered);
The error I get is #1111 - Invalid use of group function
. I had a look at THIS thread but I'm not sure how to apply the answer to my problem.
PHP:
while ( $booking_result = xtc_db_fetch_array($booking_customers_id) ) {
foreach ($booking_result as $value) {
$update_bp = xtc_db_query("
SET @ned = (SELECT max(date_altered) FROM bp_booking WHERE customers_id='".$value."');
UPDATE bp_booking SET `current_bonuspoints`= (SELECT customers_bonus_points FROM customers WHERE customers_id='".$value."') WHERE `customers_id`='".$value."' AND date_altered=@ned;");
}
}
I tried the code above but nothings happens.