Jump to content
Larry Ullman's Book Forums

Having Trouble With Select Count With Where Modifier


Recommended Posts

I just can't get this to work:

 

$q = "SELECT COUNT('current_member') AS 'current_member_count' FROM ".DBTABLE. "WHERE current_member = 'Yes'";

$r = @mysqli_query ($dbc, $q);

$row = @mysqli_fetch_array ($r, MYSQLI_ASSOC);

$records = $row['current_member_count'];

 

echo '<br /><h1>There are '.$records.' members in the MAA</h1>';

 

//An error occurred in script '/ApacheServer/ApacheDocRoot/phpPNEdevelopment/Gill/member_list.php' on line 20: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given//

 

If I take off the . "WHERE current_member = 'Yes'"

everything works fine.

 

thanks, chop

Link to comment
Share on other sites

Thank you. I did get it to work through some trial and error as follows:

 

$q = "select COUNT(*)  FROM ".DBTABLE." WHERE current_member ='Yes'";
$r = mysqli_query ($dbc, $q);
$row = mysqli_fetch_array ($r, MYSQLI_NUM);
$records = $row[0];

 

I took out the AS clause and added (*) to count and made the array NUM instead of ASSOC

 

The following still does NOT work. I'm not sure why (using ASSOC):

 

$q = "select COUNT(*)  FROM ".DBTABLE." AS YAK WHERE current_member ='Yes'";
$r = mysqli_query ($dbc, $q);
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
$records = $row['YAK'];
echo '<br /><h1>There are '.$records.' members in the MAA</h1>';

Link to comment
Share on other sites

 Share

×
×
  • Create New...