Birdman203 Posted July 6, 2006 Share Posted July 6, 2006 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 https://forums.phpfreaks.com/topic/13895-explode-or-something-like-that/ Share on other sites More sharing options...
Gast Posted July 6, 2006 Share Posted July 6, 2006 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 querymysql_query("UPDATE...");?>[/code]Hope that helps. :) Link to comment https://forums.phpfreaks.com/topic/13895-explode-or-something-like-that/#findComment-54129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.