What is the problem with mysql_num_row?
Posted: Fri Aug 16, 2002 2:39 pm
I wrote a script, shown below:
<?
if ($province=="") $prov="";
else $prov="Place=".$province."and";
if ($ground=="") $grnd="";
else $grnd="Ground=".$ground."and";
if ($border=="") $brdr="";
else $grnd="Border="."$border"."and";
if ($pattern=="") $pat="";
else $pat="Pattern=".$pattern."and";
if ($material=="") $raw="";
else $raw="Raw=".$material."and";
if ($medallion !="Y") $med="";
else $med="Medallion=".$medallion."and";
if ($round !="Y") $circle="";
else $circle="Circle=".$round;
// End of setting up query
$query="SELECT Image, Description, FROM carpet WHERE ".$prov.$grnd.$brdr.$pat.$raw.$med.$circle;
if (substr($query, -3)=="and")
for($i=1; $i<4; $i++)
$query=substr_replace($query, "", -1);
echo $query;
//require("include/db.php"); // Connect to databse
$db = mysql_pconnect("localhost");
if(!$db)
{
echo'<p><b><font face="Verdana"><font color="#FF0000">Error: </font><font color="#000080">Sorry, but can\'t connect to Database. Please try again later.</font></font></b></p>';
exit;
}
mysql_select_db ("carpets");
$result = mysql_query ($query); // Running the query
$amount = mysql_num_rows ($result); // Counting the number of raws returned by query
echo $amount;
?>
But PHP show me an error message:
SELECT Image, Description, FROM carpet WHERE Place=Ardebil
Warning: Supplied argument is not a valid MySQL result resource in C:\apache\htdocs\website\persian carpets inc\1.php on line 37
What is the problem? How can I count number of results?
<?
if ($province=="") $prov="";
else $prov="Place=".$province."and";
if ($ground=="") $grnd="";
else $grnd="Ground=".$ground."and";
if ($border=="") $brdr="";
else $grnd="Border="."$border"."and";
if ($pattern=="") $pat="";
else $pat="Pattern=".$pattern."and";
if ($material=="") $raw="";
else $raw="Raw=".$material."and";
if ($medallion !="Y") $med="";
else $med="Medallion=".$medallion."and";
if ($round !="Y") $circle="";
else $circle="Circle=".$round;
// End of setting up query
$query="SELECT Image, Description, FROM carpet WHERE ".$prov.$grnd.$brdr.$pat.$raw.$med.$circle;
if (substr($query, -3)=="and")
for($i=1; $i<4; $i++)
$query=substr_replace($query, "", -1);
echo $query;
//require("include/db.php"); // Connect to databse
$db = mysql_pconnect("localhost");
if(!$db)
{
echo'<p><b><font face="Verdana"><font color="#FF0000">Error: </font><font color="#000080">Sorry, but can\'t connect to Database. Please try again later.</font></font></b></p>';
exit;
}
mysql_select_db ("carpets");
$result = mysql_query ($query); // Running the query
$amount = mysql_num_rows ($result); // Counting the number of raws returned by query
echo $amount;
?>
But PHP show me an error message:
SELECT Image, Description, FROM carpet WHERE Place=Ardebil
Warning: Supplied argument is not a valid MySQL result resource in C:\apache\htdocs\website\persian carpets inc\1.php on line 37
What is the problem? How can I count number of results?