Connecting Tech Pros Worldwide Forums | Help | Site Map

how to convert mysql null as 0 in php

Newbie
 
Join Date: Nov 2008
Posts: 14
#1: Feb 26 '09
hi,
i am executing a query in php.
the query returns a result set which may contain NULL for some of the columns

i want to display this result set as a table.

when a column has null value i want to display it as 0

here i am not allowed to use any conditional statement.

so is there any built in function either in php or mysql that solves my problem

thanks for any help

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#2: Feb 26 '09

re: how to convert mysql null as 0 in php


what about type casting:
Expand|Select|Wrap|Line Numbers
  1. echo ((int) $var_that_may_be_null);
  2. // prints the variable as integer
Reply