6
Ola would like to know if it is possible to make a loop using while
as follows I need the array values $newsmedias1
be placed in the while
in order to perform the appearance of items with the IDS determined in the Array
provided that they are equal to the IDS of the table medias column id. I am currently performing the loop using the foreach
.
To $news['valores']
contains table numbers news column values separated by comma example 256,458,300 etc these values are the corresponding ids of the table medias column id this way when applying these values apply them to explode then performs the loop.
Code with use of foreach
<?php
// IDS da Tabela media coluna valores
$newsmedias1 = trim($news['valores'], ', ' );
// Aplica explode para separar os valores por virgula
$newsmedias2 = explode("," , $newsmedias1);
// Filtra somente valores completos
$mediaID = array_filter($newsmedias2);
foreach ($mediaID as $item)
{
$sql = $MySQLiconn->query("SELECT * FROM medias WHERE id = '$item'");
$row = $sql->fetch_array()
echo $nome;
}
?>
The problem is that this mode is not being very efficient because if I want to show 45 items will hold 45 queries and this weighing very would like to make it work using while
in order to perform a single query showing all the results in the same way as the use of foreach.
Tried a
WHERE IN(?,? ... ?)
?– rray
I don’t understand why
WHERE IN
does not apply in your case.– rray