Jump to content

Supplied argument is not a valid MySQL, It just worked for crying out loud!


Recommended Posts

Working on some pagination stuff and then all of the sudden I get this error:


Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\All Users\Desktop\Keep\Data\Server\Tests\alignment\index.php on line 24

I find this odd because it was working literally minutes ago!? What I didn’t change anything on that line how can this be?

So anyone know what’s wrong?

Here’s the code

[code]
<center>
<title>Sorry Attempt At Pagination</title>
<?php
$database_hostname = "localhost";
$database_username = "root";
$database_password = "";

if(!isset($_GET['number']))
{
    $number = "1";
}
else
{
    $number = $_GET['number'];
}

$max_results = 10;
$from = (($page * $max_results) - $max_results);

mysql_connect($database_hostname,$database_username,$database_password) or die("Unable to Connect to the MYSQL Database!");
mysql_select_db("site") or die("Unable to Select the Database!");
$query = "SELECT * FROM home ORDER BY id DESC LIMIT $from, $max_results" or die("Unable to Query!");
$result = mysql_query($query);
$num = mysql_numrows($result); # Line 24, btw
mysql_close();

for ($i = "0"; $i < $num; $i++)
{
$declare = mysql_result($result, $i, "declare");
$text = nl2br(mysql_result($result, $i, "text"));

echo "<table border='1' cellspacing='0' cellpadding='3' bordercolor='#000000' width='75%'>\r\n";
echo "<caption>".$declare."</caption>\r\n";
echo "<tr>\r\n";
echo "<td>".$text."</td>\r\n";
echo "</tr>\r\n";
echo "</table>\r\n";
echo "<br />\r\n";
}

$total_pages = ceil($num / $max_results);

echo "<table border='1' cellspacing='0' cellpadding='3' bordercolor='#000000' width='75%'>\r\n";
echo "<caption>Previous Updates:</caption>\r\n";
echo "<tr>\r\n";
echo "<td>"; for ($i = "1"; $i <= $total_pages; $i++){if (($number) == $i){echo "Page ".$i." ";}else{echo "<a href='".$_SERVER['PHP_SELF']."?number=".$i."'>Page ".$i."</a> ";}} echo "</td>\r\n";
echo "</tr>\r\n";
echo "</table>\r\n";
?>
</center>
[/code]
Change this:
[code]$query = "SELECT * FROM home ORDER BY id DESC LIMIT $from, $max_results" or die("Unable to Query!");
$result = mysql_query($query);[/code]

To this:
[code]$query = "SELECT * FROM home ORDER BY id DESC LIMIT $from, $max_results";
$result = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);[/code]
Hmmmm... Thats ugly!
error:
Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 1 with query SELECT * FROM home ORDER BY id DESC LIMIT -10, 10

"-10"!??!??!? what tha?

whats 10*1-10? 0????

Oh, Ok I figuered it out! Thanks That new error thingy narrowed down my little problem!

Thanks again!
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.