problem with My sql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

problem with My sql query

Post by manojsemwal1 »

hi i have a query where i have count and sum of the columns.
but if data is not in column its showing null value

query are like

$sql=mysql_query("SELECT count(*), sum(`Classrooms`),sum(`Male_teaching`),sum(`Female_teaching`),sum(`Total`),sum(boys1+ girls1+boys2+girls2+boys3+girls3+boys4+girls4+boys5+girls5+boys6+girls6+boys7+girls7+boys8) as st FROM `dies_tb` where School_desc='$j' and blockcode='$pid' and Clustercode='$cid'");

count(*) sum(`Classrooms`) sum(`Male_teaching`) sum(`Female_teaching`) sum(`Total`) st
0 NULL NULL NULL NULL NULL

when i see the value in table its show nothing ,i want to show 0 value if value is not there.............

Pl Help

Thanks
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: problem with My sql query

Post by litebearer »

Perhaps psudeo code...
if variable <1 echo "0" else echo variable
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: problem with My sql query

Post by McInfo »

MySQL Manual: COALESCE()
Post Reply