I am having a problem. I get this error message:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 66
I believe my syntax is wrong in the query.
Here is the script:
<?php # view_mystars.php
// This page allows users to view information about the stars they have a presence at.
// Include the configuration file for error management and such.
// require_once ('../includes/config.inc');
// Set the page title and include the HTML header.
$page_title = 'View the Stars';
include_once ('../includes/model_header.html');
// If no civname variable exists, redirect the user.
if (!isset($_SESSION['civname'])) {
header ("Location: [url]http://[/url]" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean(); // Delete the buffer.
exit(); // Quit the script.
}
else
{
$uid = ($_SESSION['user_id']);
require_once ('../../mysql_connect.php'); // Connect to the database.
// Number of records to show per page:
$display = 15;
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
}
else
{ // Need to determine.
$query = "SELECT location_id FROM users_status_micro WHERE user_id='$uid'"; // Standard query.
$query_result = mysql_query ($query);
$my_locations = @mysql_query ($query);
$query = "SELECT star_id AS starid FROM stars_status WHERE location_id='$my_locations' ORDER BY star_id ASC"; // Standard query.
$query_result = mysql_query ($query);
$num_records = @mysql_num_rows ($query_result);
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
}
else
{
$num_pages = 1;
}
}
// Determine where in the database to start returning results.
if (isset($_GET['s'])) { // Already been determined.
$start = $_GET['s'];
} else {
$start = 0;
}
// Make the query.
$query = "SELECT star_name, star_type, luminosity, star_id FROM stars_status WHERE location_id='$my_locations' LIMIT $start, $display ORDER BY star_id ASC";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows ($result); // How many stars are there?
if ($num > 0)
{ // If it ran OK, display the records.
echo "<h1>Stars Present</h1>";
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo '<p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button.
if ($current_page != 1)
{
echo '<a href="view_mystars.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++)
{
if ($i != $current_page)
{
echo '<a href="view_mystars.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
}
else
{
echo $i . ' ';
}
}
// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="view_mystars.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>';
}
echo '</p><br />';
} // End of links section.
// Table header.
echo '<table align="left" cellspacing="2" cellpadding="2">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Type</b></td><td align="left"><b>Luminosity</b></td></tr>';
// Fetch and print all the records.
$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
echo '<tr bgcolor="', $bg, '"><td align="left">', stripslashes($row[0]), '</td><td align="left">', $row[1], '</td><td align="left">',$row[2],'</td></tr>
';
}
echo '</table>'; // Close the table.
mysql_free_result ($result); // Free up the resources.
}
else
{ // If there are no registered users.
echo '<h3>You could not recieve this information due to technical difficulties. Sorry.</h3>';
}
mysql_close(); // Close the database connection.
}
include_once ('../includes/model_footer.html'); // Use the HTML footer file.
?>