cyprus Posted September 25, 2006 Share Posted September 25, 2006 The statement Select Count(*) FROM Table. How do you get a count for [b]certain[/b] records in a table? ie what would the syntax be for eg Towns. Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted September 25, 2006 Share Posted September 25, 2006 [code]SELECT COUNT(Towns) AS towncount FROM tbl;[/code] Quote Link to comment Share on other sites More sharing options...
thepip3r Posted September 25, 2006 Share Posted September 25, 2006 From thorpe's example, the PHP variable $towncount would have the number you're looking for after the query is run. Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 26, 2006 Share Posted September 26, 2006 [quote author=thepip3r link=topic=109485.msg441381#msg441381 date=1159227435]From thorpe's example, the PHP variable $towncount would have the number you're looking for after the query is run.[/quote]actually, you'd have to extract the result from the query:[code]<?php$sql = mysql_query("SELECT COUNT(Towns) AS towncount FROM tbl");$count = mysql_result($sql, 0, 'towncount');echo $count;?>[/code]another thought: if you're wanting to just count the DISTINCT towns, you may be able to just do something like this (although, i'm not sure if it's any more efficient): [code]<?php$sql = mysql_query("SELECT DISTINCT(Towns) FROM tbl");$towncount = mysql_num_rows($sql);echo $towncount;?>[/code] Quote Link to comment 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.