robert_gsfame Posted December 1, 2009 Share Posted December 1, 2009 I wish to tell all members about ticket that is available. When registered, members are given an option to choose which destination (country) information they wish to get. If they chose more than one country then all will be stored into my database with xx,yy,zz format eg: Brazil, United States, Mexico <?php require_once('config.php'); $query1="SELECT * FROM ticket"; $sql=mysql_query("SELECT * FROM passenger LIMIT 2 OFFSET 0 "); while($array1=mysql_fetch_assoc($sql)){ $subscountry1=$array1['subs_country']; $subscountry2= explode(",", $subscountry1); for($i = 0; $i < count($subscountry2); $i++){ $subscountry[$i] = $subscountry2[$i]; $query_action1=mysql_query($query1); $num1=mysql_num_rows($query_action1); if(!empty($num1)){ while($array=mysql_fetch_assoc($query_action1)){ $id=$array['id']; $registration=$array['reg_no']; $country=$array['country']; $email=$array1['email']; if($subscountry[$i]==$country){ echo $id." ".$registration." ".$country." "; }}}} mail($email,"xxxxxx","xxxxxx","xxxxxx")."<br>"; } ?> This will result : All registration number and country will appeared together with user email which is used for mail() But the problem is that $email still appear (which means that mail() will be still executed) although no records was found Can anyone help me arrange this code, they must be wrongly looped thanks Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 firstly, please put your code in code tags. and for the love of god, format your code! You have 4 ending curly braces on 1 line! Its very hard to read your code, but i did notice that your mail function is inside the while loop. is this how you intended it to be? besides that I don't see much wrong, but again, I can't really read the code Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 I wish to tell all members about ticket that is available. When registered, members are given an option to choose which destination (country) information they wish to get. If they chose more than one country then all will be stored into my database with xx,yy,zz format eg: Brazil, United States, Mexico <?php require_once('config.php'); $query1="SELECT * FROM ticket"; $sql=mysql_query("SELECT * FROM passenger LIMIT 2 OFFSET 0 "); while($array1=mysql_fetch_assoc($sql)){ $subscountry1=$array1['subs_country']; $subscountry2= explode(",", $subscountry1); for($i = 0; $i < count($subscountry2); $i++){ $subscountry[$i] = $subscountry2[$i]; $query_action1=mysql_query($query1); $num1=mysql_num_rows($query_action1); if(!empty($num1)){ while($array=mysql_fetch_assoc($query_action1)){ $id=$array['id']; $registration=$array['reg_no']; $country=$array['country']; $email=$array1['email']; if($subscountry[$i]==$country){ echo $id.$registration.$country; }}}} mail($email,"xxxxxx","xxxxxx","xxxxxx")."<br>"; } ?> This will result : All registration number and country will appeared together with user email which is used for mail() But the problem is that $email still appear (which means that mail() will be still executed) although no records was found I have to loop the email and the only problem is i don't want the email to appear if no records found Please help me in solving this code! which part is wrong and where it should be placed?? Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 Really confused :'( :'( :'( Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 I took the liberty of formatting your code. <?php $query1="SELECT * FROM ticket"; $sql=mysql_query("SELECT * FROM passenger LIMIT 2 OFFSET 0 "); while($array1=mysql_fetch_assoc($sql)){ $subscountry1=$array1['subs_country']; $subscountry2= explode(",", $subscountry1); for($i = 0; $i < count($subscountry2); $i++){ $subscountry[$i] = $subscountry2[$i]; $query_action1=mysql_query($query1); $num1=mysql_num_rows($query_action1); if(!empty($num1)){ while($array=mysql_fetch_assoc($query_action1)){ $id=$array['id']; $registration=$array['reg_no']; $country=$array['country']; $email=$array1['email']; if($subscountry[$i]==$country){ echo $id.$registration.$country; } } } } mail($email,"xxxxxx","xxxxxx","xxxxxx")."<br>"; } ?> From what I see, it shouldn't mail anything if there were no records found in the database, as the mail function itself is inside the while loop (which won't run if there are no entries returned. but, you should turn error reporting on. there is a syntax error here mail($email,"xxxxxx","xxxxxx","xxxxxx")."<br>"; That doesn't even really make sense Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 Not solving the problem yet mikesta, i try to change mail() function with echo $email to see whether $email will be executed or not and yet echo $email still appear when no records was found Something wrong with the loop, and i still cannot find which part!! Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 Oh, I didn't even look at your query. You are selecting everything from the table. As long as there is information in the table, there will be some data taken from the table. if you want to add some limitations on what is retrieved, then you need to use a WHERE clause in your query. Right now, your query is taking the first 2 rows from the table. Your Loop is actually perfectly fine. If the query doesn't return any rows, than no emails will be sent Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 LOOP PROBLEM! As it still gives me $email although there is no records Can anyone help me by giving the code?? Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 ... I told you, you need to change your query, because the query is ALWAYS retrieving 2 rows from table (assuming the table has data) If your table has data, then two emails will be sent. If you don't want emails to always be sent, then you need to add a WHERE clause to your query Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 which one mikesta?? cannot find it myself :'( Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 .... do you read your own code. The query you are using for the loop. $sql=mysql_query("SELECT * FROM passenger LIMIT 2 OFFSET 0 "); Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 yes i know, but then where should i place that query as i have to loop it to get users' email? Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 1, 2009 Share Posted December 1, 2009 your not moving the query, your simply adding an extra clause Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 Still don't get it, could anyone come up with my code that have been modified??? Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 REALLY GETTING CRAZY WITH THIS STUPID LOOP!!!! Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 1, 2009 Share Posted December 1, 2009 Dude your loop is fine, are you even reading the replies? Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 1, 2009 Author Share Posted December 1, 2009 If you never try it, then it seems to be fine but once you try it then you will find that there must be something wrong with the loop as second email always appear !!!!! eg: 123-Australia email@yahoo.com 456-Brazil email@gmail.com If there is a record then no problem with it, but when there is no record let say email@gmail.com never choose Brazil during registration n this will show up 123-Australia email@yahoo.com email@gmail.com --------------> I WANT TO KICK THIS STUPID OUT 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.