Jump to content

What is wrong with my code? Please help


ChaosKnight

Recommended Posts

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...  :wtf:

 

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...  :confused:

 

Thanks

Link to comment
Share on other sites

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  ;D

 

Thanks

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.