How to manage 0 values to "-" for Aantal

How to manage 0 values to “-” for field Aantal, if Value > 0 must show value

 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["Merk"].'</td>
    <td>'.$row["Type"].'</td>
    <td align="center">'.$row["Vermogen"].'</td>
    <td align="right"> '.$row["Prijs"].',00 &euro;</td>
    <td align="center">'.$row["Aantal"].'</td>  
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

Thanks

What have you tried?

Hello,

I tried differents codes of If - else
But none of them were working…
So if ‘.$row[“Prijs”].’ = 0 I like to have “-”
and also with ‘.$row[“Aantal”].’

Gr Marc.

Below code without the changes:

 $search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "
  SELECT * FROM tblOmvTk 
  WHERE Merk LIKE '%".$search."%'
  OR Type LIKE '%".$search."%' 
  OR Vermogen LIKE '%".$search."%' 
  OR Prijs LIKE '%".$search."%' 
 ";
}
else
{
 $query = "
  SELECT * FROM tblOmvTk  ORDER BY Merk
 ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
 $output .= '
  <div class="table-responsive">
   <table class="table table bordered">
    <tr>
     <th>Merk</th>
     <th>Type</th>
     <th>Vermogen</th>
     <th>Prijs</th>
     <th>Aantal</th> 
    </tr>
 ';


 while($row = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$row["Merk"].'</td>
    <td>'.$row["Type"].'</td>
    <td align="center">'.$row["Vermogen"].'</td>
    <td align="right"> '.$row["Prijs"].',00 &euro;</td>
    <td align="center">'.$row["Aantal"].'</td>  
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

don’t use select * but write out all necessary columns. you can use expressions in mysql

case
 when prijs = 0 then '-'
end

https://dev.mysql.com/doc/refman/5.7/en/case.html

Sponsor our Newsletter | Privacy Policy | Terms of Service