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. 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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