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 ,3
where 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
Post a Comment