RON_ron Posted October 5, 2009 Share Posted October 5, 2009 Why isn't it working??? <?php $link = mysql_connect("localhost","inmy","inmypw1"); mysql_select_db("inmy_dyomails"); $query = 'SELECT * FROM dyomails'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<dyomails>\n"; var = mystring $mystring = $urlText; $findme = '/?'; $pos = strpos($mystring, $findme); while($line = mysql_fetch_assoc($results)) { if (in_array("$pos",$line["ID"])) echo "<item>" . $line["Email"] . "</item>\n"; } while($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } echo "</dyomails>\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi What are you expecting it to do and what is it doing. It is only going to execute the first loop as by the time it gets to the 2nd it has already got all the rows from $result. All the best Keith Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 5, 2009 Share Posted October 5, 2009 var = mystring What's that supposed to do? Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 I'm sending a URL to the PHP file. And here's what I expect it to do. Extract the string and pass on the ID to my MySQL database, in the database match the ID with and get the relevant Email. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 Mchl... Oops! just ignore it. I was just trying things! the code worked with out the extracting and the matching part. But I dont dont know how to EXTRACT the querystring (ID) and make it match with the Mysql database ID to get the relevat Email. As mentioned This Code Works but I need to add the extracting and matching the db ID and returning the email part. <?php $link = mysql_connect("localhost","inmy","inmypw1"); mysql_select_db("indico_dyomails"); $query = 'SELECT * FROM dyomails'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<dyomails>\n"; while($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } echo "</dyomails>\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi There is no need to get everything from the database and check if it matches. Just bring back the (single?) matching row. Something like this should do it:- <?php $link = mysql_connect("localhost","inmy","inmypw1"); mysql_select_db("inmy_dyomails"); $query = 'SELECT * FROM dyomails'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<dyomails>\n"; $mystring = $urlText; $findme = '/?'; $pos = strpos($mystring, $findme); if ($pos !== false) { $pos += 2; $SomeVar = mysql_real_escape_string(substr($mystring,$pos)); $query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'"; $results = mysql_query($query); if($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } } echo "</dyomails>\n"; mysql_close($link); ?> All the best Keith Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 That's very cleaver! Thanks! Let me give it a try and be back to praise you more! or with something to clarify. I've beed pulling my hair for almost 5 hours now!!!!! Thanks! Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 I need a return value to tell flash it's successful. so i added the $sentOK. But it's not working. CODE: <?php $link = mysql_connect("localhost","inmy","inmypw01"); mysql_select_db("inmy_dyomails"); $query = 'SELECT * FROM dyomails'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<dyomails>\n"; $mystring = $urlText; $findme = '/?'; $pos = strpos($mystring, $findme); if ($pos !== false) { $pos += 2; $SomeVar = mysql_real_escape_string(substr($mystring,$pos)); $query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'"; $results = mysql_query($query); if($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } } $sentOk = ["Email"]; echo "</dyomails>\n"; mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi I have no idea how to pass a field back to flash. However I am pretty certain you cannot just assign a php field and have it passed back like that. Also you probably want to set $sentOK to a blank at the start of the script and then put $sentOk = $line["Email"]; inside the if statement once you have found a matching record. All the best Keith Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 can't I have the emails in the PHP and then make the match? Because this is a bit complicated. Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 What's the difference between A & B. Is B correct? A: while($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } B: $urlText = $mystring; $findme = '/?'; $pos = strpos($mystring, $findme); if ($pos !== false) { $pos += 2; $SomeVar = mysql_real_escape_string(substr($mystring,$pos)); $query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'"; $results = mysql_query($query); if($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["Email"] . "</item>\n"; } Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi A is a very small part of B. Although A is looping round all possible matches while B is using IF and just getting the first match. You can do it in php but it would be inefficient. For example if you had a million possible email addresses you would bring them all back and then loop through them to find a match (which would take ages and use a large amount of memory), whereas using sql you will just bring back the single one you are interested in. All the best Keith Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 I'm feeling so much tired now by trying to fix this!!!! Howcome A got $results & $line and B doesnt have them??? Also I'm wondering if there's something wrong in this piece of code which is blocking the entire Code. urlText = The full URL from flash | The URL is: www.myweb.com/cotton.html/?ASD123456 & MySQL ID no is ASD123456 $urlText = $mystring; $findme = '/?'; $pos = strpos($mystring, $findme); Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Howcome A got $results & $line and B doesnt have them??? B does have them. All B is doing is extracting the passed ID field (ie, locates "/?" in the URL you have passed, adds 2 to the position if found and then gets everything after that). It then looks for that particular ID within the ID field of the table. I might have been confusing you using mail_list table rather than dyomails. Bit of commented code to explain it a bit better:- <?php $link = mysql_connect("localhost","inmy","inmypw1"); mysql_select_db("inmy_dyomails"); echo "<?xml version=\"1.0\"?>\n"; echo "<dyomails>\n"; // Assign the passed URL into $mystring (not sure where you are passing it from) $mystring = $urlText; $findme = '/?'; // Locate the /? in the url $pos = strpos($mystring, $findme); // If the /? has been found (if it hasn't then $pos is set to false) if ($pos !== false) { // Add 2 to the position $pos += 2; // Extract everything after /? from the passed URL. Escape it to remove any control characters $SomeVar = mysql_real_escape_string(substr($mystring,$pos)); // Find any records from the table where the ID is the passed parameter $query = "SELECT * FROM dyomails WHERE ID = '$SomeVar'"; $results = mysql_query($query); // Get the first returned record, if one is found if($line = mysql_fetch_assoc($results)) { // Output the first returned record echo "<item>" . $line["Email"] . "</item>\n"; } } echo "</dyomails>\n"; mysql_close($link); ?> All the best Keith Quote Link to comment Share on other sites More sharing options...
RON_ron Posted October 5, 2009 Author Share Posted October 5, 2009 That explains everything!! I had a 2 hour break! I'm back. THANKS MAN!! 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.