Back again with query problems and row problems

Back again with query problems and row problems

am 21.07.2009 22:39:59 von tmiller

Okay I'm back guys...not sure what happened it was working..now it's all hu=
ng up...
Here are the errors:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result re=
source in /var/www/vhosts/getpublished.news-leader.com/httpdocs/Restur antIn=
spections/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/Restur an=
tInspections/restaurants.php on line 488



Here is the full code snippet:

=
=
=
=
=
=
// Check if page is set to show all =
if(isset($_GET['show']) && $_GET['show'] == 'all') =
{ unset($_SESSION[=
'results']); unset($_SESSION['searchna=
me']); unset($_SESSION['address']); =
=
} =
// Check if there was an empty search sent =
if(isset($_SESSION['noVarsSent'])) =
{ echo "<=
p>No values were submitted for the search.

"; =
// Unset it so a reload of page doesn't redisplay the err=
or unset($_SESSION['noVarsSent']); =
// unset($_SESSION['results']); =
} =
// Check if ful=
l 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 rang=
e if (!(isset($rangenum))) =
{ $rangenum =
=3D 1; } =
// Grab all restaurants in alphabetical order =
$sql =3D "SELECT ID, name, address, inDate, inType, notes, =
critical, cviolations, noncritical FROM restaurants, inspections WHERE rest=
aurants.name !=3D '' AND restaurants.ID =3D inspections.ID ORDER BY name;";=
$result =3D mysql_query($sql); =
//trying t=
o grab it by ranges from the db? $rows =
=3D mysql_num_rows($sql); $page_rows =
=3D 100; $last_row =3D ceil($rows/$pag=
e_rows); =
if ($rangenum < 1) { =
$rangenum =3D 1; =
} elseif ($rangenum > $last_row)=
{ =
$rangenum =3D $last_row; } =
//This se=
ts the range to display in our query $=
max =3D 'limit ' .($rangenum - 1) * $page_rows .',' .$page_rows; =
=
// Proces=
s all results into $_SESSION array =
$position =3D 1; =
while ($row =3D mysql_f=
etch_array($result)) { =
$_SESSION['fullRestaurantList'][$position] =3D $row; =
$position++; =
} =
$_SESSION['totalNumberOfRestaurants'] =3D $position; =
} =
?>

It's like 15min til 4pm here in Missouri and I am so out the door at 4..bec=
ause this has been one long frustrating day..and this girl needs a beer....=
..or two.
Talk to you all tomorrow!
Terion

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Back again with query problems and row problems

am 21.07.2009 23:10:26 von List Manager

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/Restur antInspections/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/Restur antInspections/restaurants.php on line 488
>
>
>
> Here is the full code snippet:
>
> set($_SESSION['searchname']); unset($_SESSION['address']);
} // Check if there was an empty search sent if(isset($_SESSION['noVarsSent'])) { echo "

No values were submitted for the search.

"; // 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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php