Problem reading 2 variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Problem reading 2 variables

Post 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]
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i dont understand your question.
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Post 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>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: Problem reading 2 variables

Post 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?
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Post 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';
eoinmick
Forum Newbie
Posts: 22
Joined: Fri Mar 26, 2004 12:30 pm

Post 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.
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post 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.
Post Reply