List:General Discussion« Previous MessageNext Message »
From:Jim Faucette Date:June 10 1999 4:40pm
Subject:Re: COUNT() - Explain please
View as plain text  
Barry wrote:
> 
> Hi All,
> I am confused about something, although I have used it in the past, I don't
> understand why it worked !!!  :)
> 
> The following snippet from another's question provides a good example:
> 
> > mysql_query(&sock, "select count(*) from products")
> >
> > result = mysql_store_result(&sock))
> >
> > oneRow = mysql_fetch_row(result);
> >
> > printf("%d", oneRow[0]);
> 
> colum[0] of oneRow holds the result from "Count(*)". Why is this? Is there
> a general explaination of this in the docs somewhere? Is it just an SQL
> rule to follow when using different functions in a query?
> 
> I've seen others use "Select Count(*) as thecnt" then reference the return
> as the variable "thecnt". How is this done?
> 
> Suppose I had two or three functions returning results, how would I
> reference the return values from each?
> 

1st MySQL ALWAYS returns data as strings, regardless of the data type.
These are returned in the order they are SELECTed. So,
SELECT "1", "2", "3";
col[0] = "1"
col[1] = "2"
col[2] = "3"

SELECT "3", "2", "1";
col[0] = "3"
col[1] = "2"
col[2] = "1"

As for using the field name (or alias), you'd use the field info and
loop thru them for the one(s) you're after.

  jim...
Thread
COUNT()Net-Lynx10 Jun
Re: COUNT()Jorge Santos10 Jun
  • Re: COUNT() - Explain pleaseBarry10 Jun
    • Re: COUNT() - Explain pleasePaul DuBois10 Jun
      • Re: COUNT() - Thanks everyoneBarry11 Jun
Re: COUNT() - Explain pleaseJim Faucette10 Jun