chop Posted February 20, 2012 Share Posted February 20, 2012 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 More sharing options...
rob Posted February 20, 2012 Share Posted February 20, 2012 Echo out the sql query and run it through the mysql client /phpmyadmin or other. Alternatively, remove the @ signs, check your php display_errors and error_reporting settings and use mysqli_error. 1 Link to comment Share on other sites More sharing options...
chop Posted February 20, 2012 Author Share Posted February 20, 2012 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 More sharing options...
rob Posted February 21, 2012 Share Posted February 21, 2012 You're assigning the YAK alias to the table. 1 Link to comment Share on other sites More sharing options...
Larry Posted February 22, 2012 Share Posted February 22, 2012 Good catch, Rob! Link to comment Share on other sites More sharing options...
Recommended Posts