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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.