View Single Post
  #2 (permalink)  
Old 2007-01-06, 01:23 AM
Xnuiem's Avatar
Xnuiem Xnuiem is offline
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

ok, first your query is wrong.

$sql2 = 'SELECT COUNT( DISTINCT `Author` ) FROM `books` LIMIT 0, 100';
should be
$sql2 = "SELECT COUNT(DISTINCT(`Author`)) FROM `books`";

No point in using a LIMIT clause when only a single row is returned due to the select clause.

Next, you need to go and read the documentation on the MySQL functions, the example you gave isnt even close. I understand how you got there, but make sure to read the docs.

Here is the correct way to do it:

$sql2 = "SELECT COUNT(DISTINCT(`Author`)) FROM `books`";
$result = mysql_query($sql2); <-- Dont need the DB connection unless you have more than one.
$count = mysql_fetch_row($result);
print("The number of Authors is " . $count); <-- echo is fine too, I just the implicit print, a throwback to Jython/JAVA/Perl
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote