Yes, query is definitely working without COUNT(*). Even in the most stripped down 
form, the query fails:

$sql = "SELECT COUNT(bandid), genre
FROM bands, genre";
while ($gen=mysql_fetch_row($result)) {
echo $gen[1];

"John W. Holmes" <[EMAIL PROTECTED]> wrote:
Mark Gordon wrote:

> I cannot seem to get a SELECT COUNT for a query from fields in two different tables 
> and a WHERE clause. Does anyone know if this is not possible with php/mysql or am I 
> doing something wrong? I have tried a number of variations on the following code:
> $sql = "SELECT COUNT(*), bandid, bandname, genre
> FROM bands, genre
> WHERE genre.genreid=$g
> AND bands.genreid=genre.genreid
> ORDER BY bandname ASC";
> $gen = mysql_fetch_row(mysql_query($sql)); 
> echo $gen[0];
> I know from documentation that COUNT works with WHERE clauses...but also from two 
> tables?

There's no reason it shouldn't work. The best way to troubleshoot these 
things is to get the query working without the COUNT(*) and make sure 
it's returning the right number of rows.

Are you even sure the query is executing? Maybe it's failing...

$result = mysql_query($sql) or die(mysql_error());
$gen = mysql_fetch_row($result);

---John Holmes...

Amazon Wishlist:

php|architect: The Magazine for PHP Professionals

PHP Database Mailing List (
To unsubscribe, visit:

Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Reply via email to