Reputation: 21
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.
Upvotes: 0
Views: 121
Reputation: 93
I think you need to update this line
$updateBookedSeats = $updateBookedSeats.$row['selected_bus_seats'];
With additional ,
at end like:
$updateBookedSeats = $updateBookedSeats.$row['selected_bus_seats'].',';
Upvotes: 1