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?
What is the problem with mysql_num_row?
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
try changing
to
Code: Select all
$result = mysql_query ($query); // Running the queryCode: Select all
$result = mysql_query("$query"); // Running the queryline 37 is?
replaceby
you forgot some spaces and strings have to be quoted in where clauses.
what will the code do if none of the parameters are set?
i.e.^ be careful - code not even tested by compiler 
Code: Select all
$amount = mysql_num_rows ($result); // Counting the number of raws returned by queryreplace
Code: Select all
$result = mysql_query ($query); // Running the queryCode: Select all
print('debug-query:'.$query.'<br/>');
$result = mysql_query ($query) or die(mysql_error());what will the code do if none of the parameters are set?
i.e.
Code: Select all
if ($province!="")
$where = "Place='$province'";
else
$where='';
if ($ground!='')
$where .= ((strlen($where)>0)? ' AND ' : '')."Ground='$ground'";
if ($border!='')
$where .= ((strlen($where)>0)? ' AND ' : '')."Border='border'";
if ($pattern!='')
$where .= ((strlen($where)>0)? ' AND ' : '')."Pattern='$pattern'";
if ($material!='')
$where .= ((strlen($where)>0)? ' AND ' : ''). "Raw='$material'";
if ($medallion =="Y")
$where .= ((strlen($where)>0)? ' AND ' : ''). "Medallion='$medallion'";
// ^^ always Medallion='Y' or not set ?
if ($round =="Y")
$where .= ((strlen($where)>0)? ' AND ' : ''). "Circle='$round'";
// End of setting up query
$query="SELECT Image, Description, FROM carpet";
if (strlen($where) > 0)
$query.=' WHERE '.$where;