Have an account? Sign in
Login  Register  Facebook
Code works but still shows a num_rows error?
Hi Everyone,

Basically i have a reward system on my website as Achievements. On the acievements page i want to display the achievment images that are unlocked and the locked image if the user has not unlocked them. The following code works but still brings back the following error:

Warning: mysql_num_rows():
supplied argument is not a valid MySQL result resource line 32
And here is the code i am using:
$selectachievement = mysql_query(\"SELECT * FROM achievementlist\");
    while($displayachievement = mysql_fetch_array($selectachievement)) {
        $achievement = $displayachievement[\'achievementName\'];
        $checkunlocked = mysql_query(\"SELECT * FROM achievements WHERE
                                         achievementName =\'$achievement\'
                                             AND achievementUser = \'$currentuser\'\");
        $achievementunlocked = mysql_num_rows($checkunlocked);
    ?>
    <td class=\"achievement\" width=\"120\" achievementname=\"
    <?php echo $displayachievement[\'achievementName\']; ?>\">
    <img src=\"<?php if ($achievementunlocked == \"1\") { 
    echo $displayachievement[\'achievementImage\']; }
    else { 
    echo \"http://clancorner.net/images/achievements/locked.png\"; } ?>\">
    </td>
    <?php
    }

Thanks in advance people!
Started: September 16, 2011 Latest Activity: September 16, 2011 php mysql_num_rows
1 Answer
just use @ to hide the errors:
<?php
$selectachievement = mysql_query("SELECT * FROM achievementlist");
    while($displayachievement = mysql_fetch_array($selectachievement)) {
        $achievement = $displayachievement['achievementName'];
        $checkunlocked = @mysql_query("SELECT * FROM achievements WHERE
                                         achievementName ='$achievement'
                                             AND achievementUser = '$currentuser'");
        $achievementunlocked = @mysql_num_rows($checkunlocked);
    ?>
    <td class="achievement" width="120" achievementname="
    <?php echo $displayachievement['achievementName']; ?>">
    <img src="<?php if ($achievementunlocked == "1") { 
    echo $displayachievement['achievementImage']; }
    else { 
    echo "http://clancorner.net/images/achievements/locked.png"; } ?>">
    </td>
    <?php
    }
?>

Posted: is_set
In: September 16, 2011

Thanks my friend, but do you know why i am getting the error?
September 16, 2011

make sure that the mysql query is valid try to write it in your phpmyadmin
September 16, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer