puja Posted April 27, 2006 Share Posted April 27, 2006 hinow ive been trying to get this search query for ages now and i cant seem to spot wot is wrong with ithave 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 workthe 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:[code]$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);[B]$num = mysql_num_rows($result);[/B]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());?>[/code]the problem with it is that it doesnt actually select any informationit 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 61There are currently no types of accommodation for the choices entered.Query was emptyLine 61 is the one in bold: $num = mysql_num_rows($result);i wud really appreciate it if some1 cud helpthanks Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/ Share on other sites More sharing options...
ober Posted April 27, 2006 Share Posted April 27, 2006 You're missing a closing single quotation mark after $pets_allowed. Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31288 Share on other sites More sharing options...
puja Posted April 27, 2006 Author Share Posted April 27, 2006 hey i think ive just been looking at it 4 too long!i was missing a ' after at the end of the query after pets_allowed so ive put that in and i put "or die(mysql_error())" after the query aswell. it got rid of the errors but it still doesnt know wot to look for.im not sure how 2 tell it to look for the rite thingat the moment it gives me the feedback:Unknown column 'select_type' in 'where clause' so it doesnt recognise that im trying to get it to use the results from the previous options in the search page Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31289 Share on other sites More sharing options...
ober Posted April 27, 2006 Share Posted April 27, 2006 No, that means you don't have a column in that table called "select_type". Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31290 Share on other sites More sharing options...
puja Posted April 27, 2006 Author Share Posted April 27, 2006 ok so if i change that to "type" which is my field name, how do i say that it needs to choose that type from the drop down list which is called "select_type"?once ive changed it to the correct field names it tells me that "query is empty" Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31315 Share on other sites More sharing options...
bbaker Posted April 27, 2006 Share Posted April 27, 2006 you also have to change select_sleeps to sleeps, select_board to boards....etc.[i]how do i say that it needs to choose that type from the drop down list which is called "select_type"?[/i]you took care of that with $type = $_POST["select_type"]; that pulls the value from your form (as long as your form method="post"). Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31319 Share on other sites More sharing options...
puja Posted April 27, 2006 Author Share Posted April 27, 2006 yeh thanks i changed all the field names to the actual onesi assumed that the $type = $_POST["select_type"]; would do that but it doesnt seem toand i have got my form method as as post aswell Link to comment https://forums.phpfreaks.com/topic/8540-still-probs-with-search-query/#findComment-31335 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.