mysql - PHP Mysqli replace comma if data is Null or empty during fetch -


have issue comma "," when fetching data if data selected id empty coma(,) shows want if data null or empty "," should not show unable do.

say selecting data for
id 1 ,2 ,3where id 1 num 6789 , id 2 has no num , id 3 has 12345

 $query="select  num euser userid in (select id master  aa='aa' , cc='cc')" ;         $data=mysqli_query($mysqli,$query)or die(mysqli_error());         $num = array();         while($row=mysqli_fetch_array($data)){             $num[] = $row['num'];          }         $numstr = implode(',', $num);           echo $numstr;      mysqli_close($mysqli); 

present output

6789,,12345

expecting output

6789,12345

use isset()

while ($row = mysqli_fetch_array($data)) {     if (isset($row['num']) && $row['num'] != "") {         $num[] = $row['num'];     } } $numstr = implode(',', $num); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

json - ORA-06502: PL/SQL: numeric or value error: character string buffer too small - Convert Clob to varchar2 -

ios - Swift Array Resetting Itself -