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. Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/ 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!!! :'( Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930550 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"] ? Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930554 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? Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930562 Share on other sites More sharing options...
ozestretch Posted October 5, 2009 Share Posted October 5, 2009 $_SERVER['QUERY_STRING'] Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930565 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); ?> Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930572 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"; } Link to comment https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-932746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.