mysql assiciation

Joined
Oct 18, 2005
Messages
181
Reaction score
0
Hey.
Im creating user table. there are country codes such as "nl.us.ws.lv.ru, etc."
I want to associatie them with country names. example: "nl = Netherlands".
How can i use code to print full name of country on the users profile page?

Thanx.
 
like that?
PHP:
$countries = array(
'nl' => 'Netherlands',
'en' => 'England'
);

//acquire user country from db. I will use static data
$user_country = 'en';

echo "Hey, I like people from {$countries[$user_country]}";
 
Last edited:
thanx for reply. but there is something different.

<?php
$conn = mysql_connect("localhost", "root", "pass");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("database")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT flag FROM `users` where name = '$user'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo '<img src="http://myadress/img/flag/f-'.$row['flag'].'.gif" />';
}
mysql_free_result($result);
?>

so it posts users flag, then im trying to post the country he is from.
select flag from users where name = '$user';

so it writes just nl after country code. i want to transform that to country name.
 
No there isn't. You can still use lexx' idea:

PHP:
$countries = array(
'nl' => 'Netherlands',
'en' => 'England'
);

$conn = mysql_connect("localhost", "root", "pass");
if (!$conn) {
       echo "Unable to connect to DB: " . mysql_error();
       exit;
   }
   if (!mysql_select_db("database")) {
       echo "Unable to select mydbname: " . mysql_error();
       exit;
   }
     $sql = "SELECT flag FROM `users` where name = '$user'";
   $result = mysql_query($sql);
   while ($row = mysql_fetch_assoc($result)) {
echo '<img src="http://myadress/img/flag/f-'.$row['flag'].'.gif" />$countries[$row['flag']]';
  }
    mysql_free_result($result);

Next time use your brain, its really not that difficult.
 
Back