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 12 of 12

Thread: search query!

  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy search query!

    hi
    im trying to do a search query for booking accommodation but it isnt working!
    it lets me view the page but it says:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\APACHE2\Apache2\htdocs\search.php on line 30
    No Record Found


    so the query is obviously wrong, i dont know what i am doing wrong tho. Line 30 is the one in bold

    my query looks like:

    $accommID = $_POST["accommID"];
    $type = $_POST["select_type"];
    $sleeps = $_POST["select_sleeps"];
    $board = $_POST["select_board"];
    $description = $_POST["description"];
    $pets_allowed = $_POST["select_pets_allowed"];

    $XX = "No Record Found";

    $query = mysql_query("SELECT * FROM accommodation WHERE $type = 'select_type' && $sleeps = 'select_sleeps' && $board = 'select_board' && $pets_allowed = 'select_pets_allowed'");
    while ($row = mysql_fetch_array($query))
    {
    $type=$row["select_type"];
    $sleeps=$row["select_sleeps"];
    $board=$row["select_board"];
    $pets_allowed=$row["select_pets_allowed"];

    print ("this is for $type, and $sleeps and $board and $pets_allowed");
    }

    //below this is the function for no record!!
    if (!$type)
    {
    print ("$XX");
    }

    i hope someone can understand wot im trying to do with it because im not sure i do anymore! this is going on my search page but i dont where the result shud be shown as the options are chosen on this page and so shud it go to another page to show the results?
    Last edited by puja; 04-24-2006 at 07:21 PM.

  • #2
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What happens if you try:
    PHP Code:
    $query mysql_query("SELECT * FROM accommodation...") or die(mysql_error()); 
    Edit: Looking over it seems you've got your column names and values mixed up, although I can't be sure. It should probably be
    Code:
    WHERE `select_type` = '$type' AND `select_sleeps` = '$sleeps' AND `select_board` = '$board' AND `select_pets_allowed` = '$pets_allowed'
    Last edited by trib4lmaniac; 04-24-2006 at 08:45 PM.

  • #3
    New to the CF scene
    Join Date
    Apr 2006
    Location
    India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You may try this

    $query = mysql_query("SELECT * FROM accommodation WHERE $type = 'select_type' AND $sleeps = 'select_sleeps' AND $board = 'select_board' AND $pets_allowed = 'select_pets_allowed'");

    I think in the given conditions are reversed.

    Greetings.

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    hi
    it still doesnt work!
    i tried both of ur suggestions and i still get the error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\APACHE2\Apache2\htdocs\search.php on line 30
    No Record Found

    maybe i am just approaching it in completly the wrong way!
    i dunno, i cant do it!!

  • #5
    New to the CF scene
    Join Date
    Apr 2006
    Location
    India
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Replace the relevant command with the following

    $query = mysql_query("SELECT * FROM accommodation WHERE select_type='$type' AND
    select_sleeps = '$sleeps' AND
    select_board = '$board' AND
    select_pets_allowed = '$pets_allowed'"
    );

    print mysql_error(); // this will give latest error, it would help if again error

    I hope this shoud work now.

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Just to get back to the basics for a second... do you have a valid mysql_connect()?

    Just to bypass any syntax worries, try a simple query like "Select * from accommodation" and add some where clauses later.

  • #7
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok ive tried all the suggestions, switching them around and everything and it still doesnt want to work!
    i dont even understand it nemore, i dont even think the structure is rite!
    im asking them to search using the drop down menu's but then i aint telling them to display it newhere....i think im trying to put it all on one page wen it shud actually b on 2. i aint sure nemore!

    ok this is all the code i have
    feel free to rip it 2 shreds!
    the connection works, i know that but i dont know about any of the rest..

    <html>
    <head>
    <title><?php echo "Search" ?></title>
    <link rel="stylesheet" type="text/css" href="template2.css">
    <head>
    <body>

    <?
    require_once("config.php");
    $connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");

    mysql_select_db($db_name, $connection);


    $self = $_SERVER['PHP_SELF'];



    $accommID = $_POST["accommID"];
    $type = $_POST["select_type"];
    $sleeps = $_POST["select_sleeps"];
    $board = $_POST["select_board"];
    $description = $_POST["description"];
    $pets_allowed = $_POST["select_pets_allowed"];


    $XX = "No Record Found";

    $query = mysql_query("SELECT * FROM accommodation WHERE $type = 'select_type' AND $sleeps = 'select_sleeps' AND $board = 'select_board' AND $pets_allowed = 'select_pets_allowed'");
    while ($row = mysql_fetch_array($query))
    {
    $type=$row["select_type"];
    $sleeps=$row["select_sleeps"];
    $board=$row["select_board"];
    $pets_allowed=$row["select_pets_allowed"];

    print ("this is for $type, and $sleeps and $board and $pets_allowed");
    }

    //below this is the function for no record!!
    if (!$type)
    {
    print ("$XX");
    }
    //end

    ?>

    <table border="1" width="100%" height="226">
    <tr>
    <td width="22%" height="91" bgcolor="#0099FF">&nbsp;
    <img alt ="[Company Logo]"
    src="file:///C:/Documents%20and%20Settings/Puja/My%20Documents/My%20Pictures/puj2.gif" width="100" height="100">
    <p>
    </td>
    <td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>&nbsp;

    <H1> Search </H1>

    </td>
    </tr>
    <tr>
    <td width="22%" height="123" bgcolor="#6699FF">&nbsp;
    <div class="buttonscontainer">
    <div class="buttons">
    <a href="gen_homepage.php">Homepage</a>
    <a href="register.php">Register</a>
    <a href="calendar.php">Calendar</a>
    <a href="weatherinfo.php">Weather Information</a>
    <a href="travelinfo.php">Travel Information</a>
    </div>
    </div>
    </td>
    <td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
    &nbsp;
    &nbsp;
    &nbsp;
    <center>
    <form name="search.php" action="<?php echo $_SERVER[PHP_SELF]; ?>" 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='Y'>Yes</option>
    <option value='N'>No</option>
    </select> &nbsp;
    <br> <br>

    Start Date: <input type="text" name ="booking_start_date"> &nbsp;
    End Date: <input type="text" name ="booking_end_date"> &nbsp;

    <center> <input type="submit" value="Search"></center>

    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>

    </form>
    </td>



    </table>


    </body>

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You're getting the query wrong.

    $query = mysql_query("SELECT * FROM table WHERE field = 'variable'");

    So
    PHP Code:
    $query mysql_query("SELECT * FROM accommodation WHERE $type = 'select_type' AND $sleeps = 'select_sleeps' AND $board = 'select_board' AND $pets_allowed = 'select_pets_allowed'"); 
    Should be
    PHP Code:
    $query mysql_query("SELECT * FROM accommodation WHERE select_type = '$type' AND select_sleeps = '$sleeps' AND select_board = '$board' AND select_pets_allowed = '$pets_allowed'"); 

  • #9
    New Coder
    Join Date
    Apr 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep. You got it Nightfire. He got the name of the table fields messed up with the data.

  • #10
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey guys
    thanks i changed that query around and i am still getting an error with that it says:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\APACHE2\Apache2\htdocs\search.php on line 30

    maybe its because i aint doing nething with the booking start and end dates.
    could anyone tell me if i am even approaching it the rite way.
    i am trying to obviously do a holiday booking system. this page i am trying to do should allow the customers to specify the accommodation they want and then the dates and it should give them the results if there is any accommodation for the dates they have chosen.
    At the momement i aint storing the dates newhere so it shud b available for any dates they chose rite?
    so the results shud show on a separate page rite?

  • #11
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok try this.
    PHP Code:
    $statment "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()); 
    what that will do is print of you mysql query. so you can see if its being filled in correctly. and then will print out information about the error

  • #12
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey
    thank you for ur suggesstion
    its just confirmed for me that it is all wrong! lol
    it says "query was empty"
    i cant do it


  •  

    Posting Permissions

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