redarrow Posted April 2, 2007 Share Posted April 2, 2007 advance thank you, I want to count all the fields that are set to one and show the total but dosent work any idears please. The below code is showing all the 1 but not as a total cheers <?php $query1="select message_error.read,message_bookings.read ,message_enquire.read from message_error,message_bookings,message_enquire"; $result1=mysql_query($query1)or die("mysql_error()"); while($x=mysql_fetch_assoc($result1)){ if($x['read']==1){ $total=count($x['read'].COUNT_RECURSIVE); echo $total; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/ Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 while($x=mysql_fetch_assoc($result1)){ if($x['read']==1){ $total++ } } echo $total; Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-219909 Share on other sites More sharing options...
.josh Posted April 2, 2007 Share Posted April 2, 2007 why don't you just use mysql's built in count function? Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-219910 Share on other sites More sharing options...
redarrow Posted April 2, 2007 Author Share Posted April 2, 2007 1176 << i get this and there only 33 of them and i tried the count built in method like this but didnt work <?php $query1="select message_error.read,message_bookings.read ,message_enquire.read as total count($total) from message_error,message_bookings,message_enquire"; $result1=mysql_query($query1)or die("mysql_error()"); while($x=mysql_fetch_assoc($result1)){ if($x['read']==1){ echo $x['total']; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-219915 Share on other sites More sharing options...
redarrow Posted April 2, 2007 Author Share Posted April 2, 2007 i am still getting 1176 where there only 33 number ones in the database wiered innit any idear please cheers. is it becouse the database field for read is set as a int dont no? <?php $query1="select count(*) as total from message_error,message_enquire,message_bookings"; $result1=mysql_query($query1)or die("mysql_error()"); while($x=mysql_fetch_assoc($result1)){ echo $x['total']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-219952 Share on other sites More sharing options...
dough boy Posted April 2, 2007 Share Posted April 2, 2007 I could be missing something but I do not see where you are using a "where" and joining all of those tables to each other (so basically it is multiplying all of your records). Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-219978 Share on other sites More sharing options...
redarrow Posted April 3, 2007 Author Share Posted April 3, 2007 solved the problam this way ok. <?php $query1="select count(*) as totala from message_bookings where message_bookings.read=1"; $result1=mysql_query($query1)or die("mysql_error()"); while($a=mysql_fetch_assoc($result1)){ $a1=$a['totala']; } ?> <?php $query2="select count(*) as totalb from message_error where message_error.read=1"; $result2=mysql_query($query2)or die("mysql_error()"); while($b=mysql_fetch_assoc($result2)){ $b1=$b['totalb']; } ?> <?php $query3="select count(*) as totalc from message_enquire where message_enquire.read=1"; $result3=mysql_query($query3)or die("mysql_error()"); while($c=mysql_fetch_assoc($result3)){ $c1=$c['totalc']; } ?> <?php $total_result=$a1+$b1+$c1; ?> <?php echo"<table align='center'><tr><td> Admin You Got $total_result New Mesaages </tr></td></table> Quote Link to comment https://forums.phpfreaks.com/topic/45294-solved-count-problams-cheers/#findComment-220365 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.