Page 1 of 1

Problem reading 2 variables

Posted: Fri Mar 26, 2004 12:30 pm
by eoinmick
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]

Posted: Fri Mar 26, 2004 12:32 pm
by Illusionist
i dont understand your question.

Posted: Fri Mar 26, 2004 12:39 pm
by eoinmick
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>

Posted: Fri Mar 26, 2004 12:42 pm
by Illusionist
what the hell?? What is your question?? And what is this code for?? You have no PHP in either of those files?? What are you trying to do?? Please try and respond with modern English.

Re: Problem reading 2 variables

Posted: Fri Mar 26, 2004 12:43 pm
by TheBentinel.com
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?

Posted: Fri Mar 26, 2004 12:49 pm
by eoinmick
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';

Posted: Fri Mar 26, 2004 12:58 pm
by eoinmick
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.

Posted: Fri Mar 26, 2004 1:02 pm
by Chambrln
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

Code: Select all

&lt;input type=text name="bookday" size="20"&gt;

or

//This sets the default value equal to the current day
&lt;input type=text name="bookday" size="20" value="&lt;? echo date("m/d/Y"); ?&gt;"&gt;


&lt;select name="weekno"&gt;
  &lt;option value="1"&gt;Week 1&lt;/option&gt;
  &lt;option value="2"&gt;Week 2&lt;/option&gt;
  &lt;option value="3"&gt;Week 3&lt;/option&gt;
  &lt;option value="4"&gt;Week 4&lt;/option&gt;
  &lt;option value="5"&gt;Week 5&lt;/option&gt;
&lt;/select&gt;
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

Code: Select all

&lt;?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&#1111;bookday]' and flightprices.weekno='$_POST&#1111;weekno]';";

$query = mysql_query($sql);

?&gt;
Not sure if that answers your question.