I have the following code:
$result7 = mysqli_query($conn, $sql7);
$resalm = mysqli_query($conn, $contalm);
$p = array();
while($row_alm = mysqli_fetch_array($resalm)) {
$p[] = $row_alm['nome'];
}
while($rows_cursos7 = mysqli_fetch_array($result7)) {
$tabela8 .= '<td><button type="button" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="top" title='.$p.'>'.$rows_cursos7['Almoço'].'</button></td>';
}
The problem is that if you do it inside the while print_r($p) it returns the data coming from the database.
But inside the button title='.$p.' it only returns array and not the data that comes from the database. Can you help?
>Solution :
If you want to show all the items from $p inside the second loop, you’ll also need to loop that array, or at least implode it (depending on the exact nature of the output you want to see).
For example:
Using implode
while($rows_cursos7 = mysqli_fetch_array($result7)) {
$tabela8 .= '<td><button type="button" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="top" title="'.implode(", ", $p).'">'.$rows_cursos7['Almoço'].'</button></td>';
}
Using a loop:
while($rows_cursos7 = mysqli_fetch_array($result7)) {
$tabela8 .= '<td><button type="button" class="btn btn-info btn-xs" data-toggle="tooltip" data-placement="top" title="';
foreach ($p as $i)
{
$tabela8 .= $i." - ";
}
$tabela8 .= '">'.$rows_cursos7['Almoço'].'</button></td>';
}
N.B. It’s unclear if this is the output you actually want, as that wasn’t clear from the question, but it shows you a couple of ways you can access the individual array elements, which you can then adapt to get the output you are really trying to achieve.