fatboymills Posted May 4, 2014 Share Posted May 4, 2014 I need to create an array (i think) with ID#s to match email addresses, so when the guys type in their ID# in my survey form, it will send to their email addres and mine also. Anyone know how? Thanks in advance Nigel Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/ Share on other sites More sharing options...
Ch0cu3r Posted May 4, 2014 Share Posted May 4, 2014 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) } Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478177 Share on other sites More sharing options...
fatboymills Posted May 4, 2014 Author Share Posted May 4, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478186 Share on other sites More sharing options...
Ch0cu3r Posted May 4, 2014 Share Posted May 4, 2014 Yes you can do that, but you'll need to manually edit the script each time to add/remove/change email addresses. Which is ok I suppose if you're only dealing with a vary small amount of addresses which wont change often. Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478188 Share on other sites More sharing options...
fatboymills Posted May 5, 2014 Author Share Posted May 5, 2014 No they don't change often, can you point me to an example script? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478196 Share on other sites More sharing options...
Ch0cu3r Posted May 5, 2014 Share Posted May 5, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/288236-php-array/#findComment-1478226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.