Jump to content


Photo

explode or something like that.


  • Please log in to reply
1 reply to this topic

#1 Birdman203

Birdman203
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 06 July 2006 - 08:32 PM

I have something like this:

<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>

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.

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 06 July 2006 - 08:38 PM

A simple way round is to set to value of the options to:

<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>

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:

<?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...");
?>

Hope that helps. :)
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users