Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 15 July 2006 - 05:32 AM

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

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

-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 15 July 2006 - 06:08 AM

Change this:
$query = "SELECT * FROM home ORDER BY id DESC LIMIT $from, $max_results" or die("Unable to Query!");
$result = mysql_query($query);

To this:
$query = "SELECT * FROM home ORDER BY id DESC LIMIT $from, $max_results";
$result = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);

Legend has it that reading the manual never killed anyone.
My site

#3 bobleny

bobleny
  • Members
  • PipPipPip
  • Advanced Member
  • 429 posts

Posted 15 July 2006 - 06:34 AM

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!
-- www.firemelt.net --
First do me a favor and read this: JavaScript is NOT Java - Then read this: www.php.net - When your done with that, read this Topic
After that, floors open. I and anyone else will be MORE than happy to answer YOUR query! [Topic Solved]
Cheer up, the worst has yet to come...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users