Jump to content

Archived

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

bobleny

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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.