Page 1 of 1

Problem with simple Looping, need helps

Posted: Mon Nov 30, 2009 6:56 pm
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

Re: Problem with simple Looping, need helps

Posted: Mon Nov 30, 2009 8:56 pm
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.

Re: Problem with simple Looping, need helps

Posted: Mon Nov 30, 2009 9:20 pm
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?