Mysql_Num_Rows Error in PHP Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d3vkit
    New Member
    • Nov 2006
    • 34

    Mysql_Num_Rows Error in PHP Script

    Alright I can not figure this one out, so I'm guessing it's some simple typo and some extra eyes will help me spot it.

    Here's the query (already connected to DB everything works in that respect):

    [php]$inactiveQuery = "SELECT userid,email_ad dress,username, signup_date FROM users WHERE activated = 0";
    $inactiveResult = mysql_query($in activeQuery) or die('error: query failed: '.mysql_error() );
    $inactiveNumRow s = mysql_num_rows( $inactiveResult ) or die('error: num_rows failed: '.mysql_error() );
    if($inactiveNum Rows==0) {
    echo "No inactive users!";
    } else {
    echo "Found users!";
    }[/php]

    Alright so this always gives an error on mysql_num_rows; it simply says, "Error: num_rows failed: ", but doesn't give me anymore than what I asked it to there; no official error or anything. I have at least one user in my table with activated = 0; everyone else is '2' (0=inactive, 1=reminded to activate, 2=active).
    I have tried this with 2 as well, and get the same result.

    I tried changing the select to say "WHERE user_level = 0", and it worked fine. Is activated some sort of reserved word? What am I doing wrong?

    Thanks in advance!
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Try calling mysql_num_rows without any arguments. I'm not sure if $inactiveResult is the proper resource type to be used as an argument to mysql_num_rows.

    Incidentally, while 'activated' is not a MySQL keyword, you can use keywords as identifiers by enclosing them in backticks. E.g.:

    [code=mysql]
    SELECT `value`, `type` FROM `Util_UserSetti ngs` WHERE `key` = 'max_connect_ti me` AND `username` = 'devTeam™' LIMIT 1;
    [/code]

    Note the use of 'key' as a column name, even though 'key' is a MySQL reserved word.

    Comment

    Working...