Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-04-2002, 02:49 PM
joyce's Avatar
Novice Webmaster
 
Join Date: Nov 2001
Location: Malaysia
Posts: 23
Rep Power: 0
joyce is on a distinguished road
retrieving select box..

i have a select box which display all the countries. when user register, they will need to choose they are from which country.

my problem is when retrieve out the country for display purpose. how am i suppose to do it?

this is part of the code:
PHP Code:
echo "<SELECT class=ft1 name=country>";
echo 
"<option>Please Select</option>";
echo 
"<option value=AF>Afghanistan</option>";
echo 
"<option value=AL>Albania</option>";
echo 
"<option value=DZ>Algeria</option>"
for normal select box, i will do something like this when retrieving..
PHP Code:
echo "<option ";
if (
$country == ''
  echo 
"selected";
echo 
">";

echo 
"<option value=AF ";
if (
$country == 'AF')
  echo 
"selected";
echo 
" >Afghanistan";

echo 
"<option value=AL ";
if (
$country == 'AL')
  echo 
"selected";
echo 
" >Albania";
echo 
"</option>"
i dowan to use this way because the country list is too long. if ihave to use this method, i wil have to do if statement for each and every country.

is there any alternative ways that i can do? shorter method?? better ways?? pls help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-04-2002, 12:59 AM
Novice Webmaster
 
Join Date: Nov 2001
Location: JHR
Posts: 89
Rep Power: 86
r0kawa is on a distinguished road
Send a message via Yahoo to r0kawa
how about doing some function.

function trans_country($code) {
switch ($code) {
case "AF":
$country = "Afghanistan";
break;
case "MY":
$country = "Malaysia";
break;
// and so on..
default:
$country = "";
break;

}// end switch
return $country;
}// end trans_country function

function return_option($code) {
echo '<option value='.$code;
echo "selected";
$country = trans_country($code);
echo ' >'.$country;
echo "</option>";
}

Jadi bila run function

return_option($code);

should do it.. but the long translation of the country still needed.. hope this help..

r0kawa
__________________
<a href="http://www.php.net.my">www.php.net.my</a>

Last edited by r0kawa; 06-04-2002 at 03:12 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-04-2002, 04:19 PM
New kid on the block
 
Join Date: Apr 2002
Location: Kuala Lumpur
Posts: 7
Rep Power: 0
genedavinci is on a distinguished road
how about this...

lets say you wanna hv malaysia selected:

$array['selected']['australia'] = "";
$array['selected']['indonesia'] = "";
$array['selected']['malaysia'] = "";
$array['selected']['thailand'] = "";
$array['selected']['singapore'] = "";

if(isset(my_country)){
$array['selected'][$my_country] = "selected";
}


<select name="my_country">
<option value="australia" <? echo $array['selected']['australia']?>>Australia
<option value="malaysia" <? echo $array['selected']['malaysia']?>>Malaysia
<option value="yyy" <? echo $array['selected']['yyyy']?>>Malaysia
<option value="xxx" <? echo $array['selected']['xxx']?>>XXX
</select>



genedavinci
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-04-2002, 04:23 PM
New kid on the block
 
Join Date: Apr 2002
Location: Kuala Lumpur
Posts: 7
Rep Power: 0
genedavinci is on a distinguished road
i think the best away is to make your list of country name in a array... do a loop to initialize the $array['selected'][countryname'], if set $my_country, update your array with selected country, do a loop again to print out your entire list of country name.


hope this will help

Last edited by genedavinci; 08-04-2002 at 04:26 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-04-2002, 01:38 AM
zaimlah's Avatar
Inspired Webmaster
 
Join Date: Jul 2001
Location: ttdi
Posts: 129
Rep Power: 91
zaimlah is on a distinguished road
OR, you could use a pre-written PHP class for displaying country select boxes. you can get a whole bunch of these kind classes (help u display forms) from this site:
http://phpclass.kiffer.idv.tw/browse.html/class/1.html

here's some direct links to a few of the scripts:
http://phpclass.kiffer.idv.tw/goto/b...ckage/129.html
http://phpclass.kiffer.idv.tw/goto/b...ckage/406.html
http://phpclass.kiffer.idv.tw/goto/b...package/5.html

also, you'll need to know how to use classes in PHP in order to properly use these scripts.

plus, to download the scripts, you'll need to register with the site, its free anyway.

good luck.
__________________
blog:zaim_bakar_blog | biz:box
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
select 2 table meiji Website Programming 5 02-02-2005 10:32 AM
select box/drop down menu hymns Website Design 4 21-07-2004 04:24 PM



All times are GMT +8. The time now is 07:55 AM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59