1
slyss
Drop down menu with unserlize function ?
  • 2008/3/9 18:28

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


Hi all

i need to create a drop down menu with this variable:

$coutries:

a:101:{s:13:"new_york_area";s:18:"002) New York Area";s:15:"other_place_usa";s:23:"003) Other place in USA";s:5:"italy";s:10:"004) Italy";s:11:"afghanistan";s:16:"006) Afghanistan";s:7:"albania";s:12:"007) Albania";s:7:"algeria";s:12:"008) Algeria";s:9:"argentina";s:14:"009) Argentina";s:9:"australia";s:14:"010) Australia";s:7:"austria";s:12:"011) Austria";s:15:"select_location";s:22:"001) Select a Location";s:7:"nothing";s:15:"005) ----------";s:7:"bahamas";s:12:"012) Bahamas";s:10:"bangladesh";s:15:"013) Bangladesh";s:7:"belgium";s:12:"014) Belgium";s:7:"bolivia";s:12:"015) Bolivia";s:18:"bosnia_herzegowina";s:27:"016) Bosnia and Herzegowina";s:6:"brazil";s:11:"017) Brazil";s:8:"bulgaria";s:13:"018) Bulgaria";s:6:"canada";s:11:"019) Canada";s:10:"cape_verde";s:15:"020) Cape Verde";s:5:"chile";s:10:"021) Chile";s:5:"china";s:10:"022) China";s:8:"colombia";s:13:"023) Colombia";s:5:"congo";s:10:"024) Congo";s:10:"costa_rica";s:15:"025) Costa Rica";s:7:"croatia";s:12:"026) Croatia";s:4:"cuba";s:9:"027) Cuba";s:14:"czech_republic";s:19:"028) Czech Republic";s:18:"dominican_republic";s:23:"029) Dominican Republic";s:5:"egypt";s:10:"030) Egypt";s:7:"estonia";s:12:"031) Estonia";s:4:"fiji";s:9:"032) Fiji";s:7:"finland";s:12:"033) Finland";s:6:"france";s:11:"034) France";s:7:"georgia";s:12:"035) Georgia";s:7:"germany";s:12:"036) Germany";s:5:"ghana";s:10:"037) Ghana";s:6:"greece";s:11:"038) Greece";s:9:"greenland";s:14:"039) Greenland";s:9:"guatemala";s:14:"040) Guatemala";s:6:"guinea";s:11:"041) Guinea";s:5:"haiti";s:10:"042) Haiti";s:9:"hong_kong";s:14:"043) Hong Kong";s:7:"hungary";s:12:"044) Hungary";s:7:"iceland";s:12:"045) Iceland";s:5:"india";s:10:"046) India";s:9:"indonesia";s:14:"047) Indonesia";s:4:"iran";s:9:"048) Iran";s:4:"iraq";s:9:"049) Iraq";s:7:"ireland";s:12:"050) Ireland";s:6:"israel";s:11:"051) Israel";s:7:"jamaica";s:12:"052) Jamaica";s:5:"japan";s:10:"053) Japan";s:6:"jordan";s:11:"054) Jordan";s:5:"kenya";s:10:"055) Kenya";s:5:"korea";s:10:"056) Korea";s:6:"kuwait";s:11:"057) Kuwait";s:9:"lithuania";s:14:"058) Lithuania";s:10:"madagascar";s:15:"059) Madagascar";s:8:"malaysia";s:13:"060) Malaysia";s:8:"maldives";s:13:"061) Maldives";s:5:"malta";s:10:"062) Malta";s:9:"mauritius";s:14:"063) Mauritius";s:6:"mexico";s:11:"064) Mexico";s:6:"monaco";s:11:"065) Monaco";s:10:"mozambique";s:15:"066) Mozambique";s:5:"nepal";s:10:"067) Nepal";s:11:"netherlands";s:16:"068) Netherlands";s:11:"new_zealand";s:16:"069) New Zealand";s:7:"nigeria";s:12:"070) Nigeria";s:8:"pakistan";s:13:"071) Pakistan";s:6:"panama";s:11:"072) Panama";s:8:"paraguay";s:13:"073) Paraguay";s:4:"peru";s:9:"074) Peru";s:6:"poland";s:11:"075) Poland";s:8:"portugal";s:13:"076) Portugal";s:7:"romania";s:12:"077) Romania";s:18:"russian_federation";s:23:"078) Russian Federation";s:12:"saudi_arabia";s:17:"079) Saudi Arabia";s:9:"singapore";s:14:"080) Singapore";s:8:"slovakia";s:13:"081) Slovakia";s:8:"slovenia";s:13:"082) Slovenia";s:7:"somalia";s:12:"083) Somalia";s:12:"south_africa";s:17:"084) South Africa";s:5:"spain";s:10:"085) Spain";s:6:"sweden";s:11:"086) Sweden";s:11:"switzerland";s:16:"087) Switzerland";s:6:"taiwan";s:11:"088) Taiwan";s:8:"thailand";s:13:"089) Thailand";s:7:"tunisia";s:12:"090) Tunisia";s:6:"turkey";s:11:"091) Turkey";s:7:"ukraine";s:12:"092) Ukraine";s:19:"united_arabemirates";s:24:"093) United ArabEmirates";s:14:"united_kingdom";s:19:"094) United Kingdom";s:7:"uruguay";s:12:"095) Uruguay";s:9:"venezuela";s:14:"096) Venezuela";s:14:"virgin_islands";s:19:"097) Virgin Islands";s:10:"yugoslavia";s:15:"098) Yugoslavia";s:5:"zaire";s:10:"099) Zaire";s:6:"zambia";s:11:"100) Zambia";s:8:"zimbabwe";s:13:"101) Zimbabwe";}


I need to create a drop down menu without using XoopsThemeForm, XoopsFormSelect, addElement, etc.

I need to create it with PHP (without Xoops's functions).

I need to have this for eg:

....
php code for unserialize variable $coutries ?
....

echo
'

Select countries...
'
;

foreach (... or for ...) {

echo
'$data[1]'

}

echo
'';


where $data[0] and $data[1] are 2 variabile from my variable $coutries serialized.

It's possible? Can you help me?

thanks a lot for your time

Stefano
[size=x-large]2008 Xoops Book[/size]

2
slyss
Re: Drop down menu with unserlize function ?
  • 2008/3/10 7:45

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


up, thanks.
[size=x-large]2008 Xoops Book[/size]

3
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/3/10 9:58

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


Hi slyss,

you do it like this:

1. assign your Array to the template:

$xoopsTpl->assign('countries', $countries);

e.g. defined like:
$countries[1]['id']=1
$countries[1]['name']="usa"

2. in the template:

<select name="country">
<{foreach 
item=ci from=$countries}>
<
option value="<{$ci.id}>"><{$ci.name}>option>
<{/foreach}>
select>


Best Regards,
Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

4
slyss
Re: Drop down menu with unserlize function ?
  • 2008/3/10 10:01

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


thanks for your reply Marco but i need to do this without smarty...
[size=x-large]2008 Xoops Book[/size]

5
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/3/10 10:48

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


Hmm, no smarty - no problem

Try it like this:
echo"countries">";
foreach (
array_keys($countries) as $j){
 echo
"$countries[id]">$countries[name]n";
}    
echo
"";


Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

6
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/3/10 10:54

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


There are some escape signs (\) lost in my last reply.

in my original this looks like:

\n


Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

7
slyss
Re: Drop down menu with unserlize function ?
  • 2008/3/10 10:58

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


thanks a lot for your fast reply but i don't understand how you can assign

$countries[name] ?
[size=x-large]2008 Xoops Book[/size]

8
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/3/10 13:33

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


This is a working example:

echo"countries">";
$countries = array();
$q 1;
$query $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("your_country_table").";
while(
$myrow = $xoopsDB->fetchArray($query) ) {
 
$countries[$q]['id'] = $myrow['CountryID'];
 
$countries[$q]['name'] = $myrow['CountryName'];
$q++;
}
    
foreach (array_keys(
$seasons) as $j) {
 
$country['id'] = $countries[$j]['id'];
 
$country['name'] = $countries[$j]['name'];
 echo"
<option value="$country[id]">$country[name]option>n";
}    
echo"
select>";


Of course you have to change the table name and the field names according to your XOOPS DB Table. In the first part the array is filled with the query data, in the second part the array data is filled into the select box.
There are many ways to fill the array depending on your application, so this is just one possible example.

Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

9
slyss
Re: Drop down menu with unserlize function ?
  • 2008/3/10 13:48

  • slyss

  • Quite a regular

  • Posts: 343

  • Since: 2006/1/26


thanks a lot but i think you haven't understand my problem:

in my first post you can see my serialized variable $coutries.

This is the problem: i can't do a query on database, but i need to load data from my variabile $coutries...
[size=x-large]2008 Xoops Book[/size]

10
mawi27
Re: Drop down menu with unserlize function ?
  • 2008/3/10 14:21

  • mawi27

  • Friend of XOOPS

  • Posts: 103

  • Since: 2006/1/1 1


I'm sorry but i cannot help you on that point. This requires a PHP expert, since the functions to split strings into arrays are not so easy to understand.

Maybe it is of some help for you to have a look here.

Good Luck

Marco
--
Match Dart!
Darts Ranking, News, Videos, Forum and more

Login

Who's Online

445 user(s) are online (339 user(s) are browsing Support Forums)


Members: 0


Guests: 445


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits