Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sorry still problems with search query!

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

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    your problem is here:

    PHP Code:
    $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"
    You're missing the closing ' off the end of '$pets_allowed'
    PHP Code:
    $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'"
    In future as or die(mysql_error()) after all your mysql_querys eg:

    $result = mysql_query($sql) or die(mysql_error());

  • #3
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey thanks
    i think ive just been looking at it 4 too long!
    i put the missing ' in and i do put the die(mysql_error()) usually, i dunno y i over looked it.
    thanks 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
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    ...ofcourse it doesnt.
    it is expecting you to specify column names in your where clause.

  • #5
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh i understand that now so ive changed them to my actual field names but i still dont understand how to tell it that although the actual field name is "type", i need it to select that type from the drop down list which is named "select_type"

    when i try the query like that is says "query was empty"

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    where type = $type is telling it to select the value that was selected in the drop down on the previous page - you set that earlier in your script with $type = $_POST['select_type']

  • #7
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi yeh but when i set it as select_type it doesnt recognise it in the query because my field name is just type so it says unknown column type

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    YOU DONT USE SELECT_TYPE AS YOUR FIELDNAME!!!
    You use your REAL fieldnames in the WHERE clause of your query and use the values passed from the form...
    Code:
    WHERE type = '$type'
    I dont know how I can make it any plainer

  • #9
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeh i know that and that is wot i have done but it still doesnt work
    it says the query is empty which is y i dont understand why it isnt working

  • #10
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    echo out the query then

  • #11
    New to the CF scene
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    get me the latest query you are using i will try to solve

  • #12
    New to the CF scene
    Join Date
    May 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    check the name of the field in the previous page

  • #13
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi
    im trying to get a booking query working
    it kinda works but how mine works is that i have an initial search page which has drop down lists for the user to search preferences of the accommodation they want and this information is taken from the accommodation table.
    the primary key for this is accommID.
    the code is:
    Code:
    <form name="search2.php" action="search_results2.php" method="POST">
              <font face="arial" size ="1">
        Type:
        <select name="select_type">
                <option value='Villa'>Villa</option>
                <option value='Caravan'>Caravan</option>
                <option value='Lodge'>Lodge</option>
              </select>
              &nbsp;
              Sleeps:
              <select name="select_sleeps">
                <option value='2'>Up to 2</option>
                <option value='4'>Up to 4</option>
                <option value='6'>Up to 6</option>
                <option value='8'>Up to 8</option>
                <option value='10'>Up to 10</option>
              </select> &nbsp; <br> <br>
              Board:
              <select name="select_board">
                <option value='Full Board'>Full Board</option>
                <option value='Half Board'>Half Board</option>
                <option value='B & B'>B & B</option>
                <option value='Self-Catering'>Self-Catering</option>
              </select> &nbsp;
              Pets Allowed:
              <select name="select_pets_allowed">
                <option value='Yes'>Yes</option>
                <option value='No'>No</option>
              </select> &nbsp;
              <br> <br>
               <center> <input type="submit" value="Search"></center>
    this search part works fine and it leads the user to the search results page which has the results of the accommodation that matches the choices that they gave.
    they can then select an accommodation that they want from the results through a radio button and then this will lead them through to the booking page.

    the code for the search results is this and it works fine i get no errors with it:



    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 accommID, type, sleeps, board, description, pets_allowed FROM accommodation WHERE type='$type' && sleeps = '$sleeps' && board='$board' && pets_allowed ='$pets_allowed'";
    $result = mysql_query ($query) or die(mysql_error());
    
    $num = mysql_num_rows($result);
    
    if ($num > 0){
                 echo "<p>There is currently $num accommodation(s). </p>\n";
                  echo '<FORM METHOD="POST" ACTION="add_book.php">';
                  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>
                  <td align=center><input type=radio name=accommID value="'.$row['accommID'].'"></td>
                  </tr>
                  ';
                  }
    
                  echo '</table>';
                  echo '&nbsp';
                  echo '<center> <input type="submit" value="Continue Booking"></center>';
                  
                  mysql_free_result($result);
                  
    
                  } else {
    
                      echo '<p class = "error">There are currently no types of accommodation for the choices entered.</p>';
                  }
    
    
                  echo '</FORM>';
    
                  mysql_close();
    ?>

    but the problem that i am having is that on the booking page the user is asked to put in the choices of the dates they want but it wont input the accommID for the accomm they have chosen the dates for.
    i have tried to pass it thru as hidden field but what happens is that it will insert one record with the accomm id but with the dates as empty and then another one with the accomm id empty but with the dates filled in

    the booking code looks like:




    Code:
    $self = $_SERVER['PHP_SELF'];
    $accommID = $_POST ["accommID"];
             $book_start = $_POST ["booking_start_date"];
             $book_end = $_POST ["booking_end_date"];
             $query = "INSERT INTO booking (booking_start_date, booking_end_date, accommID) VALUES ('$book_start','$book_end','$accommID')";
    
             mysql_query($query, $connection) or die (mysql_error());
    ?>
    the primary key for booking table is bookingID and the foreign key is accommID so that i can link the 2 tables.

    if ne1 has any ideas how to solve this the help wud be much appreciated! (sorry about the really long message!)
    thanks for your help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •