hey everyone. im in the process of learning MySQL with PHP from a book, and one of the example scripts doesnt seem to be working. The problem lies in the built-in function 'mysql_num_rows()'. part of the example script is listed below with the 'mysql_num_row()' function. Can anyone let me know what I'm getting wrong here? when the php script is run, i get the following displayed in my browser:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
this is an excerpt of the php script:
mysql_select_db("books"
$query = "select * from books where ".$searchtype." like '%".searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i<$num_results; $i++){
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Author: ";
echo htmlspecialchars(stripslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars(stripslashes($row["isbn"]));
echo "<br>Price: ";
echo htmlspecialchars(stripslashes($row["price"]));
echo "</p>";
}
thanks,
REI
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
this is an excerpt of the php script:
mysql_select_db("books"
$query = "select * from books where ".$searchtype." like '%".searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i<$num_results; $i++){
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row["title"]));
echo "</strong><br>Author: ";
echo htmlspecialchars(stripslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars(stripslashes($row["isbn"]));
echo "<br>Price: ";
echo htmlspecialchars(stripslashes($row["price"]));
echo "</p>";
}
thanks,
REI