I have 15 students registered in the tablealumnos
From the following query:
$stmt = $con->prepare("SELECT id FROM alumnos");
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows>0) {
$stmt->bind_result($id);
while ($stmt->fetch()) {
//
}
$stmt->close();
}
How can I get all student id separated by comma minus the last id?
Show this result
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
This can be done using implode() , but you should first get the values into a
array
.If you are only going to use the id you can rely on fetch_all() to get all the returned results and on implode to join them by commas.
Once you have the results of your query in an array:
Use Mysql for what you need GROUP_CONCAT.