Jump to content

PHP array?


fatboymills

Recommended Posts

Store the id and associated email address in a database. You'd then query the database and return the email address where the id matches,

 

example query

$mysqli->conect('localhost', 'user', 'pass', 'db');
$res = $mysqli->query($con, 'SELECT email FROM users WHERE id = ' . intval($users_id));

if($res && $res->num_rows > 0)
{
   list($email) = $res->fetch_row();

   // do something with $email (will contain the associated email address)
}
Link to comment
https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478177
Share on other sites

An example would be

// list of emails with associated id
$emails = array();
$emails['25457'] = "[email protected]";
$emails['35685'] = "[email protected]";
$emails['39697'] = "[email protected]";

// email id passed in the query string?
if(isset($_GET['id']))
{
   // retrieve the email id
   $email_id = intval($_GET['id']);

   // is there an email associated with that email id?
   if(isset($emails[ $email_id ]))
   {
      // retrieve the associated email
      $email = $emails[ $email_id ];

      // do something with $email
   }
}

An example link would be like

<a href="contact.php?id=25457">Contact me on Address 1</a>
Link to comment
https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478226
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.