--
----------
Dan Barton
Terrestrial Program Biologist
Asst. Data Manager
Point Reyes Bird Observatory
http://www.prbo.org
[EMAIL PROTECTED]
[EMAIL PROTECTED]

--- Begin Message ---
Try:

select sum(if(whatever=whatever,1,0)) as whatever from wherever where
whatever=whatever;

This is a pretty fast command for simple cross-tabs (outperforms left join?) and
is easier to understand for a quick fix. You can also write a loop that creates
a query with multiple rows like:

select sum(if(whatever=whatever,1,0)) as whatever1
select sum(if(whatever=whatever,1,0)) as whatever2
select sum(if(whatever=whatever,1,0)) as whatever3
select sum(if(whatever=whatever,1,0)) as whatever4 from wherever where
whatever=whatever group by whatever;

yay!
-db

"Martin E. Koss" wrote:

> I have read the parts of the manual(s) but am just not grasping something...
>
> I have 2 tables, one holds the Property ID etc., and the other holds all the
> Property Details. They are connected by a field called 'PropertyID' which is
> a unique ID that appears in both records.
>
> I want to count the number of records in PropertyDetails that have an entry
> in a field called 'Image1Desc', but I need to do this based on a previously
> chosen field from Property called 'PropertyType'. However, the code below is
> simply not giving the results I need:
>
> $phselect = "select COUNT(*) AS phTotal from properties LEFT JOIN
> propertydetails ON properties.PropertyID=propertydetails.PropertyID where
> ((propertydetails.Image1Desc='') AND
> (properties.PropertyType='$PropertyType'))";
>
> $phresult = mysql_query ($phselect,$conID);
>         while ($phrow = mysql_fetch_array($phresult)) {
>         $phTotal = $phrow["phTotal"];
>         PRINT "<td align=\"right\">$phresult</td>\n";
>         } // end WHILE
>
> Is there an obvious problem here and can anyone help?
>
> Martin E. Koss
> M: 07946-706459
> E: [EMAIL PROTECTED]
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
----------
Dan Barton
Terrestrial Program Biologist
Asst. Data Manager
Point Reyes Bird Observatory
http://www.prbo.org
[EMAIL PROTECTED]
[EMAIL PROTECTED]



--- End Message ---
-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to