Cooper94 Posted April 13, 2009 Share Posted April 13, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/ Share on other sites More sharing options...
MasterACE14 Posted April 13, 2009 Share Posted April 13, 2009 do... <?php $result = mysql_query("SELECT * FROM flights LIMIT 1"); Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808564 Share on other sites More sharing options...
revraz Posted April 13, 2009 Share Posted April 13, 2009 LIMIT 1 will only return 1 result, regardless of the ICAO, use DISTINCT instead. Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808572 Share on other sites More sharing options...
Cooper94 Posted April 13, 2009 Author Share Posted April 13, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808590 Share on other sites More sharing options...
premiso Posted April 13, 2009 Share Posted April 13, 2009 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']}"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808594 Share on other sites More sharing options...
Cooper94 Posted April 13, 2009 Author Share Posted April 13, 2009 Sadly that didnt work either if any one has any more suggestions please anything will help! Thank You Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808597 Share on other sites More sharing options...
premiso Posted April 13, 2009 Share Posted April 13, 2009 $result = mysql_query($query) or die("SQL Used: {$query} <br />ERROR WAS: " . mysql_error()); See if there is an error in the sql then. Quote Link to comment https://forums.phpfreaks.com/topic/153853-more/#findComment-808601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.