timmah1 Posted December 15, 2007 Share Posted December 15, 2007 I'm trying to count how many members are in my database according to what the user selected. Here is my code while($row = mysql_fetch_array( $rs )){ $member_count = mysql_fetch_assoc(mysql_query("SELECT count(*) as num FROM group WHERE name = '$row[group]'")); I'm getting the error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/god/pages/page.viewgroups.inc.php on line 37 Is there a problem that I'm just not seeinig? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/ Share on other sites More sharing options...
rarebit Posted December 15, 2007 Share Posted December 15, 2007 a bit more code might be helpful, especially the line which includes this bit 'mysql_num_rows()', y'know, the bit the error refers to! Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415677 Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 sorry $sql = "SELECT * FROM groups WHERE id = '$group'"; $result = mysql_query($sql); //$member_count = mysql_fetch_assoc(mysql_query("SELECT count(*) as num FROM group WHERE group = '$group'")); //Create a PS_Pagination object $pager = new PS_Pagination($conn,$sql,8,3); //The paginate() function returns a mysql result set $rs = $pager->paginate(); while($row = mysql_fetch_array($s)){ //while($row = mysql_fetch_array($rs)) { $member_count = mysql_fetch_assoc(mysql_query("SELECT count(*) as num FROM group WHERE name = '$row[group]'")); Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415679 Share on other sites More sharing options...
revraz Posted December 15, 2007 Share Posted December 15, 2007 You still didn't post your mysql_num_rows code. Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415690 Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 $sql = "SELECT * FROM groups WHERE id = '$group'"; $result = mysql_query($sql); $numberall = mysql_numrows($result); if ($numberall==0) { echo "<strong>No groups with that ID.</strong>"; } //$member_count = mysql_fetch_assoc(mysql_query("SELECT count(*) as num FROM group WHERE group = '$group'")); //Create a PS_Pagination object $pager = new PS_Pagination($conn,$sql,8,3); //The paginate() function returns a mysql result set $rs = $pager->paginate(); while($row = mysql_fetch_array($result)){ //while($row = mysql_fetch_array($rs)) { $member_count = mysql_fetch_assoc(mysql_query("SELECT count(*) as num FROM group WHERE name = '$row[group]'")); Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415695 Share on other sites More sharing options...
revraz Posted December 15, 2007 Share Posted December 15, 2007 mysql_numrows should be mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415696 Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 I changed that, and I still get this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415697 Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 Try $test = mysql_query("SELECT count(*) as num FROM group WHERE group = '$group'") or die(mysql_error()); And tell us what it says Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415718 Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 this is what i get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group WHERE group = '8'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415763 Share on other sites More sharing options...
phpSensei Posted December 15, 2007 Share Posted December 15, 2007 this is what i get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group WHERE group = '8'' at line 1 I think group is a reserved word in SQL. Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415767 Share on other sites More sharing options...
timmah1 Posted December 15, 2007 Author Share Posted December 15, 2007 I think your right. I changed the database name to groups_members, and everything works fine. Thank you to all who have helped, it works good now Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-415771 Share on other sites More sharing options...
revraz Posted December 16, 2007 Share Posted December 16, 2007 You could also use back ticks around group and it would have worked. `group` Quote Link to comment https://forums.phpfreaks.com/topic/81822-solved-can-you-tell-me-whats-wrong/#findComment-416049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.