Jump to content

explode or something like that.


Birdman203

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.
Link to comment
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. :)
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.