I am working on a simple flights database using mysql, php and html. My problem is;
On the Day and Week search I want the user to be able to select these from the form through option boxes.
MONDAY - FRIDAY and weeks in advance 1-5
so when the the query is ran both these variables are used??
I simply only know how to query using the "input=text" but that is only using 1 variable and the search would be insufficient!
Any ideas...thanks[/b]
Problem reading 2 variables
Moderator: General Moderators
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
have this code maybe might help to understand problem?
Only for the day search used a textbox
<!------------------------------------------------------------
Bookday&Week.php
----------------------------------------------------------
<HTML>
<HEAD><TITLE> Bookday & Week </TITLE></HEAD>
<body bgcolor="#ffffff" text="#000000">
<h2>Bookday & Week SEARCH</h2>
<form action="bookday&weekresults.php" method="get">
Query: <input name="query" type= "text" /><br/>
Search By: <select name="type">
<option value="1">Week1</option>
<option value="2">Week2</option>
<option value="3">Week3</option>
<option value="4">Week4</option>
<option value="5">Week5</option>
</select><br/>
<input type="submit" value="search" />
</form>
</body>
</html>
-->
<!------------------------------------------------------------
bookday&Weekresults.php
------------------------------------------------------------>
<HTML>
<HEAD><TITLE> Bookday & Week </TITLE></HEAD>
<body bgcolor="#ffffff" text="#000000">
<h2>Bookday & Week Results</h2>
<table border="1" cellpadding="3" cellspacing="1">
<tr><th>destinationfrom</th><th>destinationtill</th><th>price</th><th>bookday</th><th>week</th></tr>
Only for the day search used a textbox
<!------------------------------------------------------------
Bookday&Week.php
----------------------------------------------------------
<HTML>
<HEAD><TITLE> Bookday & Week </TITLE></HEAD>
<body bgcolor="#ffffff" text="#000000">
<h2>Bookday & Week SEARCH</h2>
<form action="bookday&weekresults.php" method="get">
Query: <input name="query" type= "text" /><br/>
Search By: <select name="type">
<option value="1">Week1</option>
<option value="2">Week2</option>
<option value="3">Week3</option>
<option value="4">Week4</option>
<option value="5">Week5</option>
</select><br/>
<input type="submit" value="search" />
</form>
</body>
</html>
-->
<!------------------------------------------------------------
bookday&Weekresults.php
------------------------------------------------------------>
<HTML>
<HEAD><TITLE> Bookday & Week </TITLE></HEAD>
<body bgcolor="#ffffff" text="#000000">
<h2>Bookday & Week Results</h2>
<table border="1" cellpadding="3" cellspacing="1">
<tr><th>destinationfrom</th><th>destinationtill</th><th>price</th><th>bookday</th><th>week</th></tr>
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
Re: Problem reading 2 variables
Are you asking how to build your SQL query?
SELECT time FROM FlightTimes
WHERE
weekday = 'Monday'
AND weeks = '2'
Are you looking for the AND to join the two items?
SELECT time FROM FlightTimes
WHERE
weekday = 'Monday'
AND weeks = '2'
Are you looking for the AND to join the two items?
I have the query; it is programming it in php using both the variables from the bookday & weekno.
Here is the query!
mysql> select destinationfrom,destinationtill,price,bookday,weekno from flights,flightprices where flights.flightid=flightprices.flightid and flights.flyday=flightprices.flyday and flightprices.bookday='from the input text of form' and flightprices.weekno='selected from from options';
Here is the query!
mysql> select destinationfrom,destinationtill,price,bookday,weekno from flights,flightprices where flights.flightid=flightprices.flightid and flights.flyday=flightprices.flyday and flightprices.bookday='from the input text of form' and flightprices.weekno='selected from from options';
sorry for not making myself clear Illusionist but i want a form named 'bookday&weekno search' were the user types into a text field the day wishing to travel and selects from options which week in advance wishing to fly.
The query then uses these variables in the query for the results page.
My problem is writing the code to read both these variables and place them in the query?
Hope that is a little clearer.
The query then uses these variables in the query for the results page.
My problem is writing the code to read both these variables and place them in the query?
Hope that is a little clearer.
to use the variables submitted by the form you need to use something like this:
php]<?php
$_POST['bookday'];
$_POST['weekno'];[
?>
This would be the form fields you would use on your page
You could change the flyday type to a dropdown also or some sort of checkboxes or whatever you are looking for in functionality.
Your sql would end up something like this
Not sure if that answers your question.
php]<?php
$_POST['bookday'];
$_POST['weekno'];[
?>
This would be the form fields you would use on your page
Code: Select all
<input type=text name="bookday" size="20">
or
//This sets the default value equal to the current day
<input type=text name="bookday" size="20" value="<? echo date("m/d/Y"); ?>">
<select name="weekno">
<option value="1">Week 1</option>
<option value="2">Week 2</option>
<option value="3">Week 3</option>
<option value="4">Week 4</option>
<option value="5">Week 5</option>
</select>Your sql would end up something like this
Code: Select all
<?php
$sql = "select destinationfrom,destinationtill,price,bookday,weekno from flights,flightprices where flights.flightid=flightprices.flightid and flights.flyday=flightprices.flyday and flightprices.bookday='$_POSTїbookday]' and flightprices.weekno='$_POSTїweekno]';";
$query = mysql_query($sql);
?>