Re: Back again with query problems and row problems
| From: | Jim Lucas | Date: | Tue, 21 Jul 2009 21:10:26 +0000 |
| Subject: | Re: Back again with query problems and row problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295654@lists.php.net to get a copy of this message | ||
Miller, Terion wrote:
> Okay I'm back guys...not sure what happened it was working..now it's all hung up...
> Here are the errors:
>
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
> /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/restaurants.php on line
> 464
>
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
> /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/restaurants.php on line
> 488
>
>
>
> Here is the full code snippet:
>
> <?php
>
>
>
>
> // Check if page is set to show all
> if(isset($_GET['show']) && $_GET['show'] == 'all')
> {
> unset($_SESSION['results']);
> unset($_SESSION['searchname']);
> unset($_SESSION['address']);
>
} // Check
if there was an empty search sent
if(isset($_SESSION['noVarsSent'])) {
echo "<p><b>No values were submitted for the
search.</b></p>"; // Unset it so a reload of
page doesn't redisplay the error
unset($_SESSION['noVarsSent']); //
unset($_SESSION['results']); }
// Check if full
list of restaurants has been created and stored yet // Store full
results in $_SESSION to limit database hits
if(!isset($_SESSION['fullRestaurantList']))
{ // List not grabbed yet, so run query and store in
$_SESSION //check for range
if (!(isset($rangenum))) {
$rangenum = 1; }
// Grab all restaurants in alphabetical order
$sql = "SELECT ID, name, address, inDate, inType, notes, critical, cviolations,
noncritical FROM restaurants, inspections WHERE restaurants.name != '' AND restaurants.ID
= inspections.ID ORDER BY name;"; $result =
mysql_query($sql); //trying
to grab it by ranges from the db? $rows = mysql_num_rows($sql);
$page_rows = 100; $last_row = ceil($rows/$page_rows);
if ($rangenum < 1)
{ $rangenum = 1;
} elseif ($rangenum > $last_row)
{ $rangenum = $last_row;
}
//This sets the range to display in our query $max =
'limit ' .($rangenum - 1) * $page_rows .',' .$page_rows;
// Process all results into $_SESSION array
$position = 1;
while ($row = mysql_fetch_array($result)) {
$_SESSION['fullRestaurantList'][$position] = $row;
$position++; }
$_SESSION['totalNumberOfRestaurants']
= $position; }
?>
>
> It's like 15min til 4pm here in Missouri and I am so out the door at 4..because this has
> been one long frustrating day..and this girl needs a beer.....or two.
> Talk to you all tomorrow!
> Terion
>
$sql = "SELECT ID, name, address, inDate, inType, notes, critical,
cviolations, noncritical FROM restaurants, inspections WHERE
restaurants.name != '' AND restaurants.ID = inspections.ID ORDER BY name;";
$result = mysql_query($sql);
Because the following line is wrong
//trying to grab it by ranges from the db?
$rows = mysql_num_rows($sql);
should be
$rows = mysql_num_rows($result);
But this is failing...
while ($row = mysql_fetch_array($result)) {
because your
$result = mysql_query($sql);
is probably failing.
Try changing the
$result = mysql_query($sql);
to
$result = mysql_query($sql) or die(mysql_error());
What ever you do, don't use this in production code. But it WILL be
useful with testing.
Jim Lucas