leequalls Posted July 29, 2009 Share Posted July 29, 2009 I am trying to get a count of how many messages a user has in the database this is the code I have: $mail = mysql_query("select count(*) from mail where to='$username'"); $inbox = mysql_result($mail); echo("View Inbox ($inbox)<br/>"); I get an error with this Warning: Wrong parameter count for mysql_result() what am I doing wrong? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/ Share on other sites More sharing options...
MadTechie Posted July 29, 2009 Share Posted July 29, 2009 Read the manual mysql_result mysql_result($mail, 0) Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885740 Share on other sites More sharing options...
leequalls Posted July 29, 2009 Author Share Posted July 29, 2009 I tried that before I wrote the post I still get this error Warning: mysql_result(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885743 Share on other sites More sharing options...
MadTechie Posted July 29, 2009 Share Posted July 29, 2009 see what error you get $SQL = "select count(*) from mail where to='$username'"; $mail = mysql_query($SQL) or die(mysql_error().$SQL); $inbox = mysql_result($mail, 0) echo("View Inbox ($inbox)<br/>"); remember TO check for reserved words, these can be resolved via back ticks (`) but its better to change the field name EDIT: MySQL 5.1 section 8.3. Reserved Words Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885747 Share on other sites More sharing options...
leequalls Posted July 29, 2009 Author Share Posted July 29, 2009 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 'to='username'' at line 1select count(*) from mail where to='username' Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885749 Share on other sites More sharing options...
MadTechie Posted July 29, 2009 Share Posted July 29, 2009 Yes I know, Hence! remember TO check for reserved words, these can be resolved via back ticks (`) but its better to change the field name EDIT: MySQL 5.1 section 8.3. Reserved Words Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885754 Share on other sites More sharing options...
leequalls Posted July 29, 2009 Author Share Posted July 29, 2009 ok thanks that fixed the problem Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885756 Share on other sites More sharing options...
MadTechie Posted July 29, 2009 Share Posted July 29, 2009 Welcome, this problem can be common hence the reason I pointed to the link, i think its better to learn then just giving the solution. Light a man a fire your keep him warm for a night, light a man on fire your keep him for for the rest of his life! Quote Link to comment https://forums.phpfreaks.com/topic/167939-solved-output-count/#findComment-885758 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.