Hello all!
I was having a hard time trying to get my pagination to work. Now the following code throws up this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

Any idea what could be the problem? Any help is much appreciated!

include ("databaseinfo.php");
//count number of records
$result = mysql_query("SELECT * FROM Property WHERE county='$county_sq' AND state='$state_sq'");
$num_rows = mysql_num_rows($result);
if (mysql_num_rows($result) == 0) 
echo "<font size=\"4\" face=\"Arial\"><center>No results were found.<br>Please <a 
href=\"http://www.thisnextpage.com/contactus.php\" target=\"blank\">Contact Us</a> to 
let us know so we can pinpoint that area<br>to help you find what you need.</center>";
//number you want to display per page
//count number of pages
//This tells us the page number of last page
//How many pages
//determine results
//This checks to see if there's a page number.  If not, it will set it to page 1.
if (isset($_GET['pagenum']))
$sql ="SELECT c.propID,c.street,c.city,c.state,c.zip,c.logname,";
$sql.=" FROM Clients AS c";
$sql.=" LEFT JOIN Features AS f ON f.propID=c.propID";
$sql.=" LEFT JOIN Photos AS p ON p.logname=c.logname";
$sql.=" LEFT JOIN Prices AS i ON i.propID=c.propID";
$sql.=" WHERE c.county='$county_sq' AND c.state='$state_sq'";
while ($row = mysql_fetch_assoc($result)) 
echo '<font size="5" 
face="Huxtable">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For Sale By Owner Property</font>';
echo '<table style="FONT-SIZE: 14pt" face="Huxtable" align=center border=0>';
echo '<tbody>';
echo "<img src='bar2.jpg'>";
while ($i<=$last)
echo "<td><a href=\"http://www.nextpage.php?
propID=$propID\"><img src='../uploads/$tempFile1' width='102' height='77'></a></td>";
echo "<td align=middle>$type<br>$beds beds, $baths baths<br>$sqft sq ft</td>";
echo "<td align=middle>$street<br>$city, $state $zip</td>";
echo "<td align=middle><a href=\"http://www.nextpage.php?
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "<img src='bar2.jpg'>";
echo "<br>";
}//End of WHILE loop.
//This shows what page user's on and total pages
echo "--Page $pagenum of $last--<p>";
//Create links
if ($pagenum ==1)
echo "<a href='{$_SERVER
['/thispage.php']}?pagenum=1'> <<-
First</a> ";
echo " ";
echo "<a href='{$_SERVER
['/thispage.php']}?pagenum=$previous'> <-
Previous</a> ";
//just a spacer
echo " ---- ";
//This checks if on last page and generates links
if ($pagenum ==$last)
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['/thispage.php']}?pagenum=$next'>Next -></a>";
echo " ";
echo " <a href='{$_SERVER['/thispage.php']}?pagenum=$last'>Last ->></a>";
8 Years
Discussion Span
Last Post by death_oclock

use: $result = mysql_query($sql) or die(mysql_error()); to see if it is an error in your query. The error is normally thrown if you don't get a valid result.


I see...I ended up running this query

if (!$result) {
    echo "Could not successfully run query from DB: " . mysql_error();

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";

And ended up getting this...

Could not successfully run query from DB: Unknown column 'c.propID' in 'field list'

Hmmm.....I'm trying to figure this all out...

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.