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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.