When I get the names and add to a variable, I can not detach them with commas normally.
- It must be by comma and dot at the end
- I can not put each name in line break using
It's hard to explain, but here's an example:
while ($listintegrantes = mysqli_fetch_array($query1)) {
$integrantes = "$integrantes" . $listintegrantes['nome'] . ",";
}
That is, this will show like this:
john, Cyrax, john2,
But I want you to stay:
john, Cyrax and john2.
How can this be done?
-SOLUTION
Here is the resolution of the problem posted above, all resolutions are correct, I have adapted to my problem so that my correct goal returns to me.
$query1 = mysqli_query($conexao, $sql1);
$integrantes = "";
$i = mysqli_num_rows($query1);
$x = 1;
while ($listintegrantes = mysqli_fetch_array($query1)) {
$integrantes = $integrantes . $listintegrantes['nome'];
if ($x < $i - 1) {//antes do penultimo
$integrantes = $integrantes . ", ";
}elseif($x == $i-1){//penultimo
$integrantes = $integrantes . " e ";
}elseif($x == $i){//ultimo
$integrantes = $integrantes . ".";
}
$x++;
}
below is the feedback from the above algorithm: Cyrax, John, Serana and Smigol.
When there is only one member record: Serana.