0

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">
<head>
	<title>New document</title>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// 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
require_once('dbconnect.php');
// 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";
?>
</body>
</html>

Thanks

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by dtidmas1
0

There is an error in your query, use:

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

and show what error message you get.

2

Replace your line 17

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

with

$booksSQL ="select class, title, author from l_stock $whereClause";
Votes + Comments
Worked a treat, thanks
This question has already been answered. 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.