Jump to content

Archived

This topic is now archived and is closed to further replies.

Birdman203

explode or something like that.

Recommended Posts

I have something like this:

[code]
<option value="1" style="padding-left: 20px; background: url(../img/flags/1.gif) no-repeat;" selected>United States</option><option value="2" style="padding-left: 20px; background: url(../img/flags/2.gif) no-repeat;" >Norway</option>
[/code]

And I need the value of it to be inserted as the ID in a table and the name of it thing which is United Stats and Norway in name.
I need this, because I have about 180 countries and I need all of them to be in a SQL database.

Share this post


Link to post
Share on other sites
A simple way round is to set to value of the options to:

[code]<option value="1|United States" style="padding-left: 20px; background: url(../img/flags/1.gif) no-repeat;" selected>United States</option>
<option value="2|Norway" style="padding-left: 20px; background: url(../img/flags/2.gif) no-repeat;" >Norway</option>[/code]

Now that the value is set to "1|United States" and all the others would be similar. When you submit the form, the value of the select field if it was called "country" for example:

[code]<?php
// The value of the countries above split by the pipe (|) character
$country = explode("|", $_POST['country']);

// The var $country is now an array
$country_id = $country[0];
$country_name = $country[1];

// Then run your MySQL query
mysql_query("UPDATE...");
?>[/code]

Hope that helps. :)

Share this post


Link to post
Share on other sites

×

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.