How to display only the completed data from a query to the bank

0

In my script, I do the query, however there are some fields that are empty and in foreach are empty spaces. How do I just get the data they have filled?

<?php

$consulta = $pdo->query("SELECT * FROM ws_so_wind WHERE ws_so_wind.id_soft = ws_soft_pos_contra.id_soft ");

foreach ($consulta as $pos) { ?>
  <li><?= $pos['pos']; ?></li> 
<?php } ?>
    
asked by anonymous 12.04.2017 / 03:08

2 answers

2

Just check that the value is not null with the empty function.

foreach ($consulta as $pos) {
  echo !empty($pos['pos']) ? "<li>{$pos['pos']}</li>" : null;
}

If the value is not empty, it displays the HTML code of the li element, otherwise nothing will be displayed.

    
12.04.2017 / 03:26
1

I've entered a condition in your code. It may be necessary to set the condition according to the contents of the table or the fields you want to skip, but this is the template:

<?php
$consulta = $pdo->query("SELECT * FROM ws_so_wind WHERE ws_so_wind.id_soft = ws_soft_pos_contra.id_soft ");

foreach ($consulta as $pos) {
    if(!empty($pos['pos'])) {
        echo "<li>" . $pos['pos'] . "</li>";
    }
} ?>
    
12.04.2017 / 03:28