Hi everyone,

The following code is returning the error message "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_u011067/public_html/displayclassbooks.php on line 24" and I'm not sure why?

Basically I have a list of classifications (for a book catalogue) and all the options work except for DISPLAY ALL BOOKS and I can't figure out why!

Any ideas? Help would be greatly appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
	<title>New document</title>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
// get the class from the request stream
$classification = $_REQUEST['class'];
if ($classification == "all") {
	$whereClause = "";
} else {
	$whereClause = "where l_stock.class=$classification";
// create an sql statement to retrieve books from that classification
$booksSQL ="select class, title, author from l_stock WHERE (l_stock.class=$classification)";
// connect to database
// execute sql statement
$rsbooks = mysql_query( $booksSQL );
// display the records
echo "<table border=\"1\">\n";
while ($booksrow = mysql_fetch_array( $rsbooks )){
	$classification = $booksrow['class'];
	$author = $booksrow['author'];
	$title = $booksrow['title'];
echo "\t<tr><td>$classification</td><td>$title</td><td>$author</td></tr>\n";
echo "</table>\n";


There is an error in your query, use:

$rsbooks = mysql_query( $booksSQL ) or die ( mysql_error() );

and show what error message you get.

Replace your line 17

$booksSQL ="select class, title, author from l_stock WHERE (l_stock.class=$classification)";


$booksSQL ="select class, title, author from l_stock $whereClause";
commented: Worked a treat, thanks +0

Thank you both! much appreciated :D