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 in /home/*******/public_html/*******/achievements.php on line 32

And here is the code i am using:

<?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
				}
			    ?>

Thanks in advance people!

Member Avatar for diafol

This error usually means that your SQL statement is wrong.

"SELECT * FROM achievements WHERE achievementName ='$achievement' AND achievementUser =            '$currentuser'"

Paste this (substitute the $currentuser and $achievement vars for existing values) into the SQL window of your MySQL GUI (e.g. phpmyadmin) and run it. See what it says.

OR echo the statement:

echo "SELECT * FROM achievements WHERE achievementName ='$achievement' AND achievementUser = '$currentuser'";

and paste this to the SQL window.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.