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!

<?php
 
include ("databaseinfo.php");
 
$county=$_GET['county_name'];
$county=htmlspecialchars($county);
$county_sq=mysql_real_escape_string($county);
 
$state=$_GET['state'];
$state=htmlspecialchars($state);
$state_sq=mysql_real_escape_string($state);
 
//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>";
exit;
}
 
//number you want to display per page
$page_rows=10;
 
//count number of pages
//This tells us the page number of last page
//How many pages
$last=ceil($num_rows/$page_rows);
 
//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']))
{
$pagenum=$_GET['pagenum'];
}
else{
$pagenum=1;
}
 
$sql ="SELECT c.propID,c.street,c.city,c.state,c.zip,c.logname,";
$sql.="f.property,f.beds,f.baths,f.sqft,";
$sql.="p.fileName1,";
$sql.="i.pric";
$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'";
$result=mysql_query($sql);
 
while ($row = mysql_fetch_assoc($result)) 
{
$propID=$row['propID'];
$street=$row['street'];
$city=$row['city'];
$state=$row['state'];
$zip=$row['zip'];
$logname=$row['logname'];
$type=$row['property'];
$beds=$row['beds'];
$baths=$row['baths'];
$sqft=$row['sqft'];
$tempFile1=$row["fileName1"];
$price=$row['price'];
}
 
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'>";
 
$i=1;
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?
propID=$propID\">$$price</a></td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "<img src='bar2.jpg'>";
echo "<br>";
 
$i++;
}//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)
{
}
else
{
echo "<a href='{$_SERVER
['/thispage.php']}?pagenum=1'> <<-
First</a> ";
echo " ";
$previous=$pagenum-1;
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>";
}
?>

Recommended Answers

All 3 Replies

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

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

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

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

Well, does the Clients table have a field named propID?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.