Rohlan Posted March 16, 2009 Share Posted March 16, 2009 Here's the code: <?php include("config.php"); include("opendb.php"); $sql="SELECT lista_emails FROM noticias WHERE id=1"; $result=mysql_query($sql); $row = mysql_fetch_array($result); echo $row['lista_emails']; echo "<hr>"; $sql2= "SELECT * FROM subscritores"; $result2=mysql_query($sql2); while($row2 = mysql_fetch_array($result2)) { $counter = $counter + 1; $lista = $row['lista_emails']; $email = $row2['email']; $pos = strpos($lista, $email); echo $counter; if ($pos === false) { echo "Enviar para '$email' "; mysql_query("UPDATE noticias SET lista_emails='".$row['lista_emails']."$email;' WHERE id=1"); } else { echo "Não enviar para '$email' "; } echo "<br>"; } include("closedb.php"); ?> The problem is the query inside my while loop... it seems to only happen once during the whole loop.. Quote Link to comment Share on other sites More sharing options...
premiso Posted March 16, 2009 Share Posted March 16, 2009 How many rows are in the subscritores table? It will only loop for how many rows are returned. Start there and make sure there is more than 1 row. Try running the SQL through phpMyAdmin, and see what returns. Quote Link to comment Share on other sites More sharing options...
Rohlan Posted March 16, 2009 Author Share Posted March 16, 2009 There are 5 rows in that table. The code generates this output when I run it: 1Enviar para 'whatever@com.com' 2Enviar para 'lol@com.com' 3Enviar para 'stff@com.com' 4Enviar para 'sdf@com.com' 5Enviar para 'ggr@com.com' And the query that's supposed to loop will run, but only once, and if I run the script again, it works again but for the next row only... it seems to only run once and only once even though its supposed to be looping.. Quote Link to comment Share on other sites More sharing options...
Rohlan Posted March 16, 2009 Author Share Posted March 16, 2009 I figured it out. I had an extra query that I used to obtain "$row['lista_emails']", I placed that query inside the while loop and it started working properly, obviously that variable needs to be updated each time the loop restarts, but this wasnt happening before because it was outside the loop. Thanks for the time. Quote Link to comment Share on other sites More sharing options...
premiso Posted March 16, 2009 Share Posted March 16, 2009 It is running each time is my guess. mysql_query("UPDATE noticias SET lista_emails='".$row['lista_emails']."$email;' WHERE id=1"); You are updating the same id each time. My bet is the last email is the one that gets posted. If you want to append (or concat) the emails to that field, you will need to do something a bit different. MySQL Concat mysql_query("UPDATE noticias SET lista_emails=CONCAT(`lista_emails`, '".$row['lista_emails']."$email;') WHERE id=1"); See if that was what you were after. Quote Link to comment Share on other sites More sharing options...
Rohlan Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks for your time premiso 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.