I have these data in my booked_tickets table:
1st Row: A1, A3, B2
2nd Row: C3, D2, A2
3rd Row: C1, A2, D1
When I tried to concatenate these data into one string, I get this: A1, A3, B2C3, D2, A2C1, A2, D1
What I wanted is: A1, A3, B2, C3, D2, A2, C1, A2, D1
How do I concatenate like that?
if (mysqli_num_rows($resultData) > 0){
while ($row = mysqli_fetch_assoc($resultData)) {
$updateBookedSeats = $updateBookedSeats.$row['selected_bus_seats'];
$updateTotalPassengers = $updateTotalPassengers + $row['number_of_passengers'];
}
mysqli_stmt_close($stmt);
$updateBookedSeats = explode(",", $updateBookedSeats);
sort($updateBookedSeats);
$updateBookedSeats = implode(",", $updateBookedSeats);
}
Ignore the $updateTotalPassengers, that works fine on its own.
$updateTotalPassengers = $updateTotalPassengers +can be simplified to$updateTotalPassengers +=you then should put a,in there. You can usertrimafter the loop to remove the last one... or$updateBookedSeatsis the same thing... and use.=for the operator.rtrimwill be safer thansubstrbecause it would only remove a trailing comma.