Hello, I would like to know if it is possible to loop using while
so I need the values of the $newsmedias1
array to be placed in while
in order to make the appearance of the items with the given IDS in the Array
as long as they are equal to the ids of the table column id column. I'm currently looping using foreach
.
The $news['valores']
contains numbers of the table news column values separated by commas example 256,458,300 etc. These values are the corresponding ids of the table average column of this form when applying these values apply them to the explode then loop.
Code using 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 very efficient because if I want to show 45 items I will have 45 queries and this is very heavy I would like to make use of while
to perform a single query showing all the results of the same form of foreach use.