...

View Full Version : search query!



puja
04-24-2006, 07:12 PM
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?

trib4lmaniac
04-24-2006, 08:42 PM
What happens if you try:


$query = mysql_query("SELECT * FROM accommodation...") or die(mysql_error());
Looking over it seems you've got your column names and values mixed up, although I can't be sure. It should probably be

WHERE `select_type` = '$type' AND `select_sleeps` = '$sleeps' AND `select_board` = '$board' AND `select_pets_allowed` = '$pets_allowed'

sakitram
04-24-2006, 08:58 PM
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.

puja
04-24-2006, 09:04 PM
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!!

sakitram
04-24-2006, 09:09 PM
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.

arnyinc
04-24-2006, 09:41 PM
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.

puja
04-24-2006, 11:23 PM
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>

Nightfire
04-25-2006, 12:42 AM
You're getting the query wrong.

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

So


$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


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

ablaye
04-25-2006, 01:41 AM
Yep. You got it Nightfire. He got the name of the table fields messed up with the data.

puja
04-25-2006, 11:48 AM
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?

MRMAN
04-25-2006, 01:23 PM
ok try this.


$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

puja
04-25-2006, 03:40 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum