Jump to content

mysql_num_rows() expects parameter 1 to be resource, boolean given


DCarl

Recommended Posts

My code is,

 

<?php
// This block allows our program to access the MySQL database.
// Stores your login information in PHP variables
require_once '223login.php';
// Accesses the login information to connect to the MySQL server using your credentials and database
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
// This provides the error message that will appear if your credentials or database are invalid
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
 
// Store the query string from 2.2.3.A Step 17
$query = "SELECT * FROM requests WHERE model_id=1";
 
// Searches the database returning results that match the query
// Results come in a table stored in $requests_for_model
$requests_for_model = mysql_query($query);
// The mysql_num_rows function returns an integer representation of number of rows for the table passed as an argument
$number_of_requests = mysql_num_rows($requests_for_model);
 
for ($current_row = 0; $current_row < $number_of_requests; $current_row++)
{
// walker variable (through rows in the table)
$request = mysql_fetch_row($requests_for_model);
// query directed to get a table containing the one row that has a store matching the store ID in the current request
$query = "SELECT * FROM store_info WHERE store_id='" . $request[1] . "'";
$store_requesting = mysql_query($query); // A table containing the store
$store = mysql_fetch_row($store_requesting); // Get the only row in the table (unique store ID number guarantees this)
echo $store[2]; // output the 2nd item in the row for that store, which is the city
if ($current_row < $number_of_requests - 1) // Makes sure commas are only printed after results that are not the last
{
echo ", ";
}
 
?>
 
I do not know how to fix this. Help much appreciated. 

 

this is a (very) common error. did you search for it to find what it means and to find out how to determine what is causing it?

 

see this link - http://forums.phpfreaks.com/topic/273121-readme-php-resources-faqs/?do=findComment&comment=1428660

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.