RON_ron Posted October 5, 2009 Share Posted October 5, 2009 I have a MySQL database. and I'm stucked with the code below (AREA MARKED IN RED). I need to get an email to the matching string. <?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 ID and get me the email. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 PLEASE SOMEBODY HELP ME.... it's a real hair puller!!! :'( Quote Link to comment Share on other sites More sharing options...
ozestretch Posted October 5, 2009 Share Posted October 5, 2009 where is $ID defined? should it be $line["ID"] ? Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 yep! you are correct. But still how to extract the quesy string from the URL for matching. while($line = mysql_fetch_assoc($results)) { if (in_array("?distributor11111111K",["ID"])) echo "<item>" . $line["Email"] . "</item>\n"; } I need advice on rewriting this part where it extracts the query string and match it with the MySQL ID field. OR do you know how to request PHP to omit the text before the "/?" sign in the query string. Then PHP could match the remaining (?distributor11111111K) which is exactly what I want? How do I write that simple line? Quote Link to comment Share on other sites More sharing options...
ozestretch Posted October 5, 2009 Share Posted October 5, 2009 $_SERVER['QUERY_STRING'] Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 I see the lighthouse now!! But do you think you could help me in fixing this code? Where The Fixing needs to be done. $sendURL = $_SERVER['QUERY_STRING'] while($line = mysql_fetch_assoc($results)) { if (in_array("['QUERY_STRING']",$line["ID"])) echo "<item>" . $line["Email"] . "</item>\n"; } It should pick only the relevent email (one email) from the database by matching the query string with the ID field in the MySQL. FULL CODE: <?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"; $URL = $_SERVER['QUERY_STRING'] while($line = mysql_fetch_assoc($results)) { if (in_array("['QUERY_STRING']",$line["ID"])) echo "<item>" . $line["Email"] . "</item>\n"; } echo "</mail_list>\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
ozestretch Posted October 8, 2009 Share Posted October 8, 2009 Sorry for delay. // assuming the ONLY thing in the query string is the ID $URL = $_SERVER['QUERY_STRING']; // changed, missing ';' while($line = mysql_fetch_assoc($results)) { if (in_array($URL,$line["ID"])) // changed from ['QUERY_STRING'] to $URL echo "<item>" . $line["Email"] . "</item>\n"; } Quote Link to comment 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.