Code: Select all
<?php
$countries = array( array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 0, 10, 6, 0, 11, 0, 4, 5) , 'country' => 'United States',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 5, 8, 8, 6, 11, 4, 4, 4) , 'country' => 'Great Britain',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 4, 5, 2, 10, 5, 6, 11, 7, 3, 4) , 'country' => 'France',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 6, 8, 4, 6, 5, 6, 8, 6, 2, 2) , 'country' => 'Spain',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 1, 4, 3, 0, 4, 1, 0, 1) , 'country' => 'Nicaragua',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 1, 7, 2, 0, 4, 0, 0, 0) , 'country' => 'Hawaii',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 1, 1, 2, 3, 0, 7, 2, 2, 2) , 'country' => 'Panama',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 0, 2, 2, 2, 2, 1, 1, 0) , 'country' => 'Jamaica',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 4, 2, 5, 0, 2, 4, 0, 0, 3, 0) , 'country' => 'India',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 1, 0, 0, 0, 0, 1, 1, 1, 2, 3) , 'country' => 'Sudan',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 1, 0, 0, 0, 1, 1, 1, 1, 1) , 'country' => 'Libya',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 0, 0, 0, 2, 2, 2, 3, 2) , 'country' => 'Algeria',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 2, 2, 0, 1, 2, 1, 0, 0) , 'country' => 'Vietnam',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 0, 3, 1, 0, 3, 2, 0, 1) , 'country' => 'Costa Rica',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 2, 2, 3, 3, 2, 0, 5, 2, 0, 1) , 'country' => 'Philippines',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 2, 6, 3, 3, 2, 2, 5, 0, 0, 2) , 'country' => 'China',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 0, 3, 3, 2, 4, 1, 0, 0) , 'country' => 'Puerto Rico',
array( 'resource' => array('Coal', 'Iron', 'Timber', 'Fruit', 'Vegetables', 'Cotton', 'Sugar', 'Tobacco', 'Silver', 'Gold'), 'amount' => array( 0, 0, 2, 5, 2, 3, 4, 2, 0, 1) , 'country' => 'Cuba');
$conn = mysql_connect("localhost", "root", "") or die('Could not connect to the database: '.mysql_error());
mysql_select_db("countries", $conn) or die('Could not select the database: '.mysql_error());
foreach ($countries as $key => $val){
$resource = $val['resource'];
$amount = $val['amount']
$country = $val['country'];
$sql = "update baseadd set '$resource' = '$amount' where convert(country using utf8) = '$country' limit 1";
$res = mysql_query($sql) or die(mysql_error().'<p>SQL:<br />'.$sql.'</p>');
}
?>