Forum Moderators: coopster
I am trying to get the following code to act as a locator file ie:
locator.php?state=NV
meaning that it displays everything from that state..
This is the error message I get on locator.php?state=NV:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/blueline/public_html/wheretobuy/editNews.php on line 20
Here is the code from the index.php page:
<?
include("../connect.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$state=$_POST['state'];
$query=" SELECT * FROM sa ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$state=mysql_result($result,$i,"state");
$company=mysql_result($result,$i,"company");
?>
<p><? echo "$company";?> <a href="locator.php?state=<?echo $state;?>"></a>
<?
++$i;
}
?>
//End Code
Here is the code to display the states (locator.php?state=NV) (example):
<?
include("../connect.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM sa WHERE state=$state";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$state=mysql_result($result,$i,"state");
$company=mysql_result($result,$i,"company");
?>
<? echo "$company";?><br />
<? echo "$address";?>
<? echo "$state";?>
<?
++$i;
}
?>
//End Code
Can anyone see my error or am I heading in the wrong direction?
Thanks
You have some error in the
$query="SELECT * FROM sa WHERE state=$state";
query
I would still change the code and would replace
$result=mysql_query($query) or die(mysql_error());
with
$result=mysql_query($query) or die("Error: ".mysql_error()."<br>SQL: ".$query);
Then see the query and spot the mistake, or send it here. The could be something in the $state variable that could spoil the query.
Kind regards
Michal Cibor