0

I'm currently working on a project where I'm creating a travel agency site using PHP and MySQL.

I've come across an issue where I want to add a search function that uses information from multiple SELECT options such as airport, location and stay length of which the corresponding information is stored in their own relevant table within MySQL.

How do I querying the database using multiple tables? I've attempted the below solution by selecting each table and column within the table with no success.

$location = $_GET['location'];
$airport = $_GET['airport'];
$stay = $_GET['stay'];
$date = $_GET['date'];

$sql = "SELECT location_name, airport__name, stay_length FROM airport, location, stay WHERE location__name =?, airport_name =?, stay_length =?";

$result = mysqli_query($conn, $sql);
echo $result;

DB Name: Flight

Table Names: location, stay, airport

Columns

location = location_id, location_name

stay = stay_id, stay_length

airport = airport_id, airport_name

Kristiono Setyadi
  • 5,635
  • 1
  • 19
  • 29
Kieren
  • 1
  • 3
    You need to learn about sql joins – John Conde Feb 21 '21 at 02:24
  • 1
    What is the relationship between `Airport` and `Location`? Does `Airport` have a `location_id`? Does `stay` have a from and to date? `stay_length` isn't really useful here, but start and end date would be. I assume that `stay` also has a `location_id` or an 'airport_id`. You need to include all of the relevant referential columns so we can help you with this query – Chris Schaller Feb 21 '21 at 03:20
  • 1
    In your post you should include a plain english description of your query, the query syntax is clearly wrong, but it's not 100% clear what you are actually trying to achieve. Do you want to find all the stays on a specific date that came through a specific airport? provide an example of the parameters you want to pass through, that will help tell your story – Chris Schaller Feb 21 '21 at 03:27
  • That dupe doesn't help OP, the issue here is the query itself, not the PHP implementation of it – Chris Schaller Feb 23 '21 at 13:15

0 Answers0