Country
RE: [PHP] Sorting Country List
Date: Wed, 25 Jun 2003 08:31:27 +0200Newsgroups: php.general
Size: 1,788 bytes
I use this code, which extracts from mysql, and you can set the option of
which you want to be selected
<?php
// List Box MySQL Functions
function listbox_field ($mysql_link, $name, $default=0) { $result="<select name=\"$name\">\n"; while (list($key,$val)=mysql_fetch_array($mysql_link)) { if ($default == $key) {$selected="selected";} else {$selected="";} $result.="<option value=\"$key\" $selected>$val</option>\n"; } $result.="</select>\n";
return $result;
}
?>
<?php
// Code in actual web page to extract the Countries $conn = db_connect(); if (!$conn) return "Could not connect to the Database - Please Try Later."; $country=mysql_query("SELECT countryid, country FROM countries"); echo listbox_field($country, "country", "UK");
?>
<?php
// DB CONNECT function
function db_connect() { $result = mysql_pconnect("<HOSTNAME>","<USERNAME>","<PASSWORD>"); if (!$result) return false; if (!mysql_select_db("<DBNAME>")) return false; return $result;
}
?>
The country table I use stores the Country Code and then the Country Name,
can send the SQL for that if you need it.
Craig
> -----Original Message-----
> From: Ralph [mailto:email-address-deleted]
> Sent: 25 June 2003 06:43
> To: PHP General Mailing List
> Subject: [PHP] Sorting Country List
>
>
> I am getting a list of all countries from mysql database, and then I am
> sorting by country name. However since most orders will be from US I
> want the US to appear first over the rest of the countries. How can I go
> about doing this?
>
> Currently, this is my query:
>
> SELECT countries_id, countries_name FROM TABLE_COUNTRIES ORDER BY
> countries_name;
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
