Problem with simple Looping, need helps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
green_coder
Forum Newbie
Posts: 7
Joined: Mon Oct 26, 2009 1:40 am

Problem with simple Looping, need helps

Post by green_coder »

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

Code: Select all

<?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."&nbsp;&nbsp;&nbsp;&nbsp;".$registration."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$country."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }
            }
        }
    }
    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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Problem with simple Looping, need helps

Post by yacahuma »

have you try to use IN in your queries??

SELECT * FROM USERS WHERE STATES IN ('Virginia','Florida').

What I am trying to say is that it seems to me that you could use less queries to accomplish the same thing.
green_coder
Forum Newbie
Posts: 7
Joined: Mon Oct 26, 2009 1:40 am

Re: Problem with simple Looping, need helps

Post by green_coder »

I think there won't be any problem with the query as those are 2 different queries, and the problem is with the loop

Can anyone help me with the code?
Post Reply