RON_ron Posted October 5, 2009 Share Posted October 5, 2009 I'm having a list of email addresses and I only want the PHP to select one of them at a time, depending on the information passed through the strings and into the form. When PHP receives the query string I would like PHP to extract it and match to an email address ("www.myweb.com/main.html?blaBLA" --> extract as "?blaBLA"). I'm using Flash (AS2) to do my form and I send data using LoadVars to PHP. Here's the pseudocode for what I'm trying to do. (I'm not sure if the syntext is correct). Please help me write this complete code. where $list = "abc" then $email = "abcd@domain1.com" where $list = "xyz" then $email = "pqurs@domain2.net" where $list = "ghi" then $email = "uvwx@domain3.org" (repeated 30 times for 30 email addresses!) I hope that make sense! I'd preffer to have the code because I'm NOT a PHP gal at all! Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/ Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 Wont work! <?php $ID=customer("?customer777777K"); if ($ID=="?customer777777K") echo "maggie@abc.com"; $ID=customer("?customer888888K"); if ($ID=="?customer8888887K") echo "james@abc.com"; //so on ?> Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930506 Share on other sites More sharing options...
RussellReal Posted October 5, 2009 Share Posted October 5, 2009 please show me an example URLRequest you use to connect to your php file.. and then give me an example of your desired output, and than I or somebody else will be able to help you better Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930511 Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 I record the URL in flash using js & flash externalinterface class. Then I send it to the PHP file (which is on the server). PHP will receieve www.myweb.com/online/pencils.html?distributor11111111K Desired output: james@abc.com -------- The method here should be; ?distributor11111111K = james@abc.com ?distributor22222222K = franklin@apx.com ?distributor33333333K = Julie@xyz.com Basically PHP should match the query string to an email address and return the email address. I hope that make more sense! Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930514 Share on other sites More sharing options...
RussellReal Posted October 5, 2009 Share Posted October 5, 2009 ok I'm gonna ask you, distributor1111111111k is that a key in an array.. or where/how do you expect to associate this with your result? is it a field in the database? a name of a file? Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930520 Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 OK... I have a MySQL database. and I'm stucked with the code below (AREA MARKED IN RED). Using that I need to achieve the above mentioned. I've got ID / NAME / EMAIL / COMPANY in my Mysql database. <?php $link = mysql_connect("localhost","myname","mypw"); mysql_select_db("my_mails"); $query = 'SELECT * FROM mail_list'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<mail_list>\n"; while($line = mysql_fetch_assoc($results)) { if (in_array("?distributor11111111K",$ID)) echo "<item>" . $line["Email"] . "</item>\n"; } echo "</mail_list>\n"; mysql_close($link); ?> I want PHP to match the query string (?distributor11111111K) with an email. Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930521 Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 So you wish to output $line['email'] only if it contains distributor11111111K? while($line = mysql_fetch_assoc($results)) { if (strpos($line["Email"], "distributor11111111K")) echo "<item>" . $line["Email"] . "</item>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930623 Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi I would try something like this:- <?php $link = mysql_connect("localhost","myname","mypw"); mysql_select_db("my_mails"); $checkField = 'MaybeSomeDefaultTarget'; foreach($_GET AS $field => $value) { $checkField = mysql_real_escape_string($field); } $query = "SELECT * FROM mail_list WHERE ID = '$checkField'"; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<mail_list>\n"; if($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } echo "</mail_list>\n"; mysql_close($link); ?> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930631 Share on other sites More sharing options...
RussellReal Posted October 5, 2009 Share Posted October 5, 2009 <?php if ($current = each($_GET)) { mysql_connect("xxxxx","xxxxxx","xxxxxxxx"); $q = mysql_query("SELECT * FROM table WHERE ID = '{$current['key']}'"); echo "<?xml version=\"1.0\"?>\n"; echo "<mail_list>\n"; if ($row = mysql_fetch_assoc($q)) { echo "<item>{$row}</item>\n"; } echo "</mail_list>"; } ?> basically the same as Keith's but a lil shorter n stuff Sorry I kinda left last night, I fell asleep I was tired. Quote Link to comment https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/#findComment-930861 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.