Jump to content

More


Cooper94

Recommended Posts

<?php
session_start();
include 'data.php';
?>
<form method="post" action="http://www.republicv.org/options.php?content=bid">
<table width=100% align=center>
<tr align=center><td width=50%>Departure Airport</td><td align=left>
<select name="dep">
<option value="all">Select All</option>
<?php 
$result = mysql_query("SELECT * FROM flights");
while ($row = mysql_fetch_array($result))
{
echo "<option value={$row['dep_icao']}>{$row['dep_icao']}</option>";
}
?>
</select>
<tr align=center><td>Arrival Airport</td><td align=left>
<select name="arr">
<option value="all">Select All</option>
<?php 
$result = mysql_query("SELECT * FROM flights");
while ($row = mysql_fetch_array($result))
{
echo "<option value={$row['arr_icao']}>{$row['arr_icao']}</option>";
}
?>
</select>
<tr align=center><td>Aircraft</td><td align=left>
<select name="aircraft">
<option value="Select Aircraft"></option>
<option value="ERJ-170/175">ERJ-170/175</option>
</select></td></tr>
<tr align=center><td></td><td align=left><input type="submit" name="submit" value="Search Timetable"></td></tr>
</form>

So I have it searching the database and putting into a option. But say there is more than one of the same dep_icao or arr_icao. It will show all the dep_icao and arr_icao is it possible to just limit it to one if there is more than one? So say there is two KDCA in the database how do I make it show just one of those in the option?

 

Thank You

Link to comment
https://forums.phpfreaks.com/topic/153853-more/
Share on other sites

Ok thank you and one more thing:

<?php
include 'data.php';
?>
<form method="post" action="http://www.flycirrusair.com/bid.php">
<table width=100% align=center>
<tr align=center><td width=50%>Departure Airport</td><td align=left>
<select name="dep">
<option value="all">Select All</option>
<?php 
$result = mysql_query("SELECT * FROM flights GROUP BY dep_icao");
while ($row = mysql_fetch_array($result))
{
echo "<option value=$row[dep_icao]>$row[dep_icao]</option>";
echo "";
}
?>
</select>
<tr align=center><td>Arrival Airport</td><td align=left>
<select name="arr">
<option value="all">Select All</option>
<?php 
$result = mysql_query("SELECT * FROM flights GROUP BY arr_icao");
while ($row = mysql_fetch_array($result))
{
echo "<option value=$row[arr_icao]>$row[arr_icao]</option>";
echo "";
}
?>
</select>
<tr align=center><td></td><td align=left><input type="submit" name="submit" value="Search Timetable"></td></tr>
</form>
<?php
if(isset($_POST['submit'])) { 
$dep = mysql_real_escape_string($_POST['dep']);
$arr = mysql_real_escape_string($_POST['arr']);

if ($dep == "all" AND $arr == "all") {
$query = "SELECT * FROM flights WHERE dep_icao LIKE '%' AND arr_icao LIKE '%' ";} 
elseif ($dep == "all" AND $arr != "all") {
$query = "SELECT * FROM flights WHERE dep_icao LIKE '%' AND arr_icao='$arr' ";} 
elseif ($dep != "all" AND $arr == "all") {
$query = "SELECT * FROM flights WHERE dep_icao='$dep' AND arr_icao LIKE '%' ";}
elseif ($dep != "all" AND $arr != "all") {
$query = "SELECT * FROM flights WHERE dep_icao='$dep' AND arr_icao='$arr' ";}
else{}

$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{ 
echo "{$row['dep_icao']}"; 
echo "{$row['arr_icao']}";
}}
?>

I keep getting this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/flycirru/public_html/bid.php on line 48

Link to comment
https://forums.phpfreaks.com/topic/153853-more/#findComment-808590
Share on other sites

If those if/elseif reaches the else $query is empty and will not return any results.

 

Change the else to this:

 

else{$query = null;}

  if (!is_null($query)) {
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result))
    { 
        echo "{$row['dep_icao']}"; 
        echo "{$row['arr_icao']}";
     }
  }
}

Link to comment
https://forums.phpfreaks.com/topic/153853-more/#findComment-808594
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.