Jump to content

still probs with search query


puja

Recommended Posts

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:

[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 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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.