puja
04-27-2006, 12:45 PM
hi
now ive been trying to get this search query for ages now and i cant seem to spot wot is wrong with it
have i just over looked something really simple or am i just doing it all wrong?
i know alot of ppl have tried helping before and i have used there suggestions but i still cant get it to work
the query is to select options from a drop down box which is on a search page and then those selections are meant to be shown on this search results page.
the thing is that i dont have the drop down boxes on the search results page, is it ok to link it from the previous page?
and shud i put the query on the search page or the search results page?
the query now looks like:
$self = $_SERVER['PHP_SELF'];
$type = $_POST["select_type"];
$sleeps = $_POST["select_sleeps"];
$board = $_POST["select_board"];
$description = $_POST["description"];
$pets_allowed = $_POST["select_pets_allowed"];
$query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE select_type = '$type' AND select_sleeps = '$sleeps' AND select_board = '$board' AND description= '$description' AND select_pets_allowed = '$pets_allowed";
$result = mysql_query ($query);
$num = mysql_num_rows($result);
if ($num > 0){
echo "<p>There is currently $num accommodation. </p>\n";
echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">
<tr>
<td align="left"><b>Type</b></td>
<td align="left"><b>Sleeps</b></td>
<td align="left"><b>Board</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Pets Allowed</b></td>
</tr>
';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo '
<tr>
<td align="left">'. $row['type']. '</td>
<td align="left">'. $row['sleeps']. '</td>
<td align="left">'. $row['board']. '</td>
<td align="left">'. $row['description']. '</td>
<td align="left">'. $row['pets_allowed']. '</td>
</tr>
';
}
echo '</table>';
mysql_free_result($result);
} else {
echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';
}
mysql_close();
$statment =mysql_query ("SELECT * FROM accommodation WHERE select_type = '$type' AND select_sleeps = '$sleeps' AND select_board = '$board' AND select_pets_allowed = '$pets_allowed'");
print $statment;
$query = mysql_query($statment) or die(mysql_error());
?>
the problem with it is that it doesnt actually select any information
it gives me the error and information:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\APACHE2\Apache2\htdocs\search_results.php on line 61
There are currently no types of accommodation for the choices entered.
Query was empty
Line 61 is the one in bold: $num = mysql_num_rows($result);
i wud really appreciate it if some1 cud help
thanks
now ive been trying to get this search query for ages now and i cant seem to spot wot is wrong with it
have i just over looked something really simple or am i just doing it all wrong?
i know alot of ppl have tried helping before and i have used there suggestions but i still cant get it to work
the query is to select options from a drop down box which is on a search page and then those selections are meant to be shown on this search results page.
the thing is that i dont have the drop down boxes on the search results page, is it ok to link it from the previous page?
and shud i put the query on the search page or the search results page?
the query now looks like:
$self = $_SERVER['PHP_SELF'];
$type = $_POST["select_type"];
$sleeps = $_POST["select_sleeps"];
$board = $_POST["select_board"];
$description = $_POST["description"];
$pets_allowed = $_POST["select_pets_allowed"];
$query = "SELECT type, sleeps, board, description, pets_allowed FROM accommodation WHERE select_type = '$type' AND select_sleeps = '$sleeps' AND select_board = '$board' AND description= '$description' AND select_pets_allowed = '$pets_allowed";
$result = mysql_query ($query);
$num = mysql_num_rows($result);
if ($num > 0){
echo "<p>There is currently $num accommodation. </p>\n";
echo '<table align = "center" border = "1" cellspacing = "0" cellpadding = "5">
<tr>
<td align="left"><b>Type</b></td>
<td align="left"><b>Sleeps</b></td>
<td align="left"><b>Board</b></td>
<td align="left"><b>Description</b></td>
<td align="left"><b>Pets Allowed</b></td>
</tr>
';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
echo '
<tr>
<td align="left">'. $row['type']. '</td>
<td align="left">'. $row['sleeps']. '</td>
<td align="left">'. $row['board']. '</td>
<td align="left">'. $row['description']. '</td>
<td align="left">'. $row['pets_allowed']. '</td>
</tr>
';
}
echo '</table>';
mysql_free_result($result);
} else {
echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';
}
mysql_close();
$statment =mysql_query ("SELECT * FROM accommodation WHERE select_type = '$type' AND select_sleeps = '$sleeps' AND select_board = '$board' AND select_pets_allowed = '$pets_allowed'");
print $statment;
$query = mysql_query($statment) or die(mysql_error());
?>
the problem with it is that it doesnt actually select any information
it gives me the error and information:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\APACHE2\Apache2\htdocs\search_results.php on line 61
There are currently no types of accommodation for the choices entered.
Query was empty
Line 61 is the one in bold: $num = mysql_num_rows($result);
i wud really appreciate it if some1 cud help
thanks