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 Link to comment https://forums.phpfreaks.com/topic/22046-select-count/ 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] Link to comment https://forums.phpfreaks.com/topic/22046-select-count/#findComment-98618 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. Link to comment https://forums.phpfreaks.com/topic/22046-select-count/#findComment-98626 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] Link to comment https://forums.phpfreaks.com/topic/22046-select-count/#findComment-98652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.