Jump to content


Photo

still probs with search query


  • Please log in to reply
6 replies to this topic

#1 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 27 April 2006 - 11:48 AM

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);

[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());

?>


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

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 April 2006 - 12:11 PM

You're missing a closing single quotation mark after $pets_allowed.

Info: PHP Manual


#3 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 27 April 2006 - 12:12 PM

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 thing
at 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

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 27 April 2006 - 12:13 PM

No, that means you don't have a column in that table called "select_type".

Info: PHP Manual


#5 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 27 April 2006 - 01:37 PM

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"




#6 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 27 April 2006 - 01:46 PM

you also have to change select_sleeps to sleeps, select_board to boards....etc.

how do i say that it needs to choose that type from the drop down list which is called "select_type"?

you took care of that with $type = $_POST["select_type"]; that pulls the value from your form (as long as your form method="post").

#7 puja

puja
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 27 April 2006 - 02:20 PM

yeh thanks i changed all the field names to the actual ones
i assumed that the $type = $_POST["select_type"]; would do that but it doesnt seem to
and i have got my form method as as post aswell




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users