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
Share on other sites

Thank you for the tip. I will try this. Althouh im curious whether it can be done inside the script like...

 

$id['25457']="user1@email.com";

$id['35685']="user2@email.com";

$id['39697']="user3@email.com";

 

And then call the $id to email.

Thanks again.

Nigel

Link to comment
Share on other sites

An example would be

// list of emails with associated id
$emails = array();
$emails['25457'] = "user1@email.com";
$emails['35685'] = "user2@email.com";
$emails['39697'] = "user3@email.com";

// 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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