Jump to content

Select Count


cyprus

Recommended Posts

[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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.