ChaosKnight Posted January 5, 2010 Share Posted January 5, 2010 Hi, the website that I'm busy with has to be done by the end of the week. The code is supposed to query for the countries in the hotels table, and then generate a select dropdown based on the result, but it returns nothing... Here is the code: $db_link = mysql_connect($db_host, $db_user, $db_pass); if ( ! $db_link ) die( "Couldn't connect to mySql Server<br />"); //echo( "Connected to mySql Server<br />"); $db_select = mysql_select_db($db); if ( ! $db_select ) die("Couldn't connect to Database<br />"); //echo("Connected to Database<br />"); echo"<form action='' method='POST'> <label for='countrySelect'>Country</label> <select id='countrySelect' name='country'>\n"; $query = "SELECT DISTINCT `country_id` FROM `hotels` ORDER BY `country_id`"; $result = mysql_query($query, $db_link); or die ("couldn't execute query."); $num_rows = mysql_num_rows($result); if ( $num_rows < 1 ) { print( "<span class=\"error_text\">NO RESULTS FOUND. Please try again...</span>" ); } else{ while($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$country_id'>$country_id</option>"; } echo "</select>"; I tried the rest of the code with a predefined array and it worked perfectly, but as soon as I change it to the above it displays nothing... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/187261-what-is-wrong-with-my-code-please-help/ Share on other sites More sharing options...
monkeypaw201 Posted January 5, 2010 Share Posted January 5, 2010 Well, for starters, the $result line should read; $result = mysql_query($query, $db_link) or die ("couldn't execute query."); Let us know if there is any output now. Quote Link to comment https://forums.phpfreaks.com/topic/187261-what-is-wrong-with-my-code-please-help/#findComment-988868 Share on other sites More sharing options...
ChaosKnight Posted January 5, 2010 Author Share Posted January 5, 2010 Thanks for the reply, that made my code a bit cleaner, but still didn't fix it, so I went through everything thoroughly and I found my problem, I forgot to put a "}" after an else statement LOL Sometimes a make the stupidest mistakes hehe Thanks Quote Link to comment https://forums.phpfreaks.com/topic/187261-what-is-wrong-with-my-code-please-help/#findComment-988892 Share on other sites More sharing options...
ChaosKnight Posted January 5, 2010 Author Share Posted January 5, 2010 But now there is another problem, the country_id returns "southafrica", but it should display "South Africa", I tried $row['country'] which should return the "South Africa" (I inserted the extra column in the database, but I guess it doesn't work because I only queried for the country_id column... Please help Oh and it should still use DISTINCT because there are several entries for South Africa and I only need to display it once in the select dropdown Thanks Quote Link to comment https://forums.phpfreaks.com/topic/187261-what-is-wrong-with-my-code-please-help/#findComment-988915 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.