Print result of an array in php list format

0

I have two arrays in php , which I compare and create a third and want to print this difference in a list.

I've tried foreach , but this method prints a huge list in string .

This is my code:

$sql = mysqli_query($cx, "SELECT IPS FROM ipvalidos ORDER BY IPS ASC ");

while($aux = mysqli_fetch_assoc($sql)) {
    $arrayip[ ] = $aux["IPS"];
        }

$diferenca = array_diff($arrayip, $arraycompara);

foreach ($diferenca as $diferencas)
{
        $stringArrayF = $stringArrayF.$diferencas;
}       
echo $stringArrayF;

The printed output exits:

192.168.0.1192.168.0.2192.168.0.3192.168.0.4192.168.0.5...

I would like to be able to put this result into a select html

<select><option value="$stringArrayF">$stringArrayF</option>;
    
asked by anonymous 08.11.2018 / 14:29

3 answers

0

<html>
$sql = mysqli_query($cx, "SELECT IPS FROM ipvalidos "); 






while($aux = mysqli_fetch_assoc($sql)) { 
	$arrayip[ ] = $aux["IPS"]; 
} 

$diferenca = array_diff($arrayip, $arraycompara); 

?> 




<body>
<select>
<?php	foreach ($diferenca as $diferencas) { 
	$stringArrayF = $stringArrayF.$diferencas; 
?> 

<option value="$diferencas"><?php echo $stringArrayF; ?></option> 

</body>


<?php } ?> 
</select>
    
08.11.2018 / 16:31
0

Try changing your foreach to this code:

echo "<select>";
foreach ($diferenca as $value)
{
    echo '<option value="'.$value.'">'.$value.'</option>';
}       
echo "</select>";
    
09.11.2018 / 01:48
-1

Do this fixed

$sql = mysqli_query($cx, "SELECT IPS FROM ipvalidos ORDER BY IPS ASC ");

while($aux = mysqli_fetch_assoc($sql)) {
    $arrayip[ ] = $aux["IPS"];
        }

$diferenca = array_diff($arrayip, $arraycompara);


?>

<?php


foreach ($diferenca as $diferencas)
{

$stringArrayF = $stringArrayF.$diferencas;
?>

<select><option value="<?php $stringArrayF ?>">$stringArrayF</option>;


<?php        
}    

?>   
    
08.11.2018 / 14:39