Jump to content

Warning: mysql_num_rows(): - TEARING HAIR OUT


widget

Recommended Posts

Heres a doosey - well for me anyway.

 

I have a cron file to clear out high scores and award a trophy to the top 3 players.

 

Now if I run the Bubble Pop cron job (top code) it works fine however if I run the Pyramid one(bottom code) it throws back an error at me

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kabooc/public_html/ghetto_cron.inc.php on line 384

 

Line 384 is  if(mysql_num_rows($result))

 

Both are the exact same code bar the second one has a WHERE clause.

 

 

if ($run['Bubblepop'])
{
$sql_query = "SELECT username,MAX(score) as total FROM highscores_bubblepop GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3";
//store the SQL query in the result variable
$result = mysql_query($sql_query);

if(mysql_num_rows($result))
{
$x =110;
while($row = mysql_fetch_row($result))
{
mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')");
mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Bubble Pop Trophy','$row[0] was awarded a $x trophy','1')");
$x ++;
}
}
mysql_query("DELETE FROM highscores_bubblepop");
}

 

if ($run['Trophy Pyramid Solitaire'])
{
$sql_query = "SELECT username,MAX(score) as total FROM highscores WHERE gameID = '106' GROUP BY username ORDER BY 'total' DESC LIMIT 0 , 3";
//store the SQL query in the result variable
$result = mysql_query($sql_query);

if(mysql_num_rows($result))
{
$x =101;
while($row = mysql_fetch_row($result))
{
mysql_query("INSERT INTO trophy (user_name, trophy_id) VALUES ('$row[0]','$x')");
mysql_query("INSERT INTO records (record_type, record_entry, userid) VALUES ('Trophy Pyramid Solitaire','$row[0] was awarded a $x trophy','1')");
$x ++;
}
}

}

 

I have looked through google and most errors I find the solution is to...

double check database tables - done

check spelling - done

check connection - done

 

is there an alternative way to do what I am trying and what is it? or is there some sort of blatantly obvious error and im just not seeing it?

Link to comment
https://forums.phpfreaks.com/topic/240872-warning-mysql_num_rows-tearing-hair-out/
Share on other sites

Your code is not checking if the query executed without any errors before attempting to access the data from the query. If you use mysql_error() in some error checking and error reporting/logging logic, it will tell you why the query is failing.

 

Are you debugging this by browsing to the file to see the errors or are you running this as a cron job and checking the php errors in the log file?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.