PHP Search Issue


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I am using the following code to search and return flights from a database. The user searches by inputting a DepID and an ArrID and I want to display only flights that match both DepID and ArrID. However at the moment I am get results only from DepID.. Im sure its something simple but any help appreciated.

Code: <?php
if(isset($_POST['submit'])){
Did you know?Explore Trending and Topic pages for more stories like this.
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['DepID'], $_POST['ArrID'])){
$DepID=$_POST['DepID'];
$ArrID=$_POST['ArrID'];
//connect to the database
$db=mysql_connect ("localhost", "HIDDEN", "HIDDEN") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("HIDDEN");
//-query the database table
$sql="SELECT FlightNo, DepID, DepTime, ArrID, ArrTime, Equip FROM routes WHERE DepID LIKE '%" . $DepID . "%' OR ArrID LIKE '%" . $ArrID ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$FlightNo=$row['FlightNo'];
$DepID=$row['DepID'];
$DepTime=$row['DepTime'];
$ArrID=$row['ArrID'];
$ArrTime=$row['ArrTime'];
$Equip=$row['Equip'];

//-display the result of the array
echo "<ul>n";
echo "<li>" .$FlightNo . " " . $DepID . " " . $DepTime . " " . $ArrID . " " . $ArrTime . " " . $Equip . "</a></li>n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
No comments posted yet

Your Answer:

Login to answer
86 Like 13 Dislike
Previous forums Next forums
Other forums

Time-based image rotation script
I'm trying to write a PHP script that rotates an image based on what time of day it is. I want the

upgrade from 4.7 to ECC 6.0
Hi all,
we are going to do an upgrade from R/3 4.7 to ECC 6.0. I need to know if i can find som

Need help to modify php ELSE code
I'm trying to find a way to have the php code display a message if there is no inventory listed in t

How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of

Time script, set to my time zone?
I am using this line to get the date and time

Code: $time = date(F." ".d.", &q

php mailer
How can i send a mail to large no, say 50,000 reciepients using [color=#0000FF]php mailer[/color]

Displaying image from database
Hi,

I've got a site where that's got a database behind it. Currently it has loads of items in

Multiple upload and Resize
I would like some help on my script I have the for my index.php

////

<html&

Staff Induction System - No idea where to go from here!!!
Hi there, I'm pretty new to PHP and Mysql so could really do with being pointed in the right directi

Query issues
I probably have this setup wrong well I know I do because nothing is showing up now. What I want is

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash