tags:

views:

44

answers:

2

Hi, sorry for my english,but I have problem because I seek the same values of field and when I find the same value I print a message , if I don t find a same values I print an error message but this error message is repated and I want to print once if they are no same values this my code:

foreach($row2 as $key => $value)
    {
        echo $value['event_title'].'<br/>';
        if(isset($_SESSION['account_id']))
        {
            $query3 = Connexion::getConnexion()->prepare('SELECT COUNT(event_id) AS nbr,account_id,event_id ,account_event_place_reserved FROM account_event WHERE account_id =:id');
            $query3->bindParam(':id',$_SESSION['account_id'],PDO::PARAM_INT);
            $query3->execute();
            $row3 = $query3->fetch(PDO::FETCH_ASSOC);
            //$query3->closeCursor();
            //print_r($row3);

            if($row3['nbr'] > 0)
            {
                $query4 = Connexion::getConnexion()->prepare('SELECT account_id,event_id ,account_event_place_reserved FROM account_event WHERE account_id =:id GROUP BY event_id');
                $query4->bindParam(':id',$_SESSION['account_id'],PDO::PARAM_INT);
                $query4->execute();
                $row4 = $query4->fetchAll(PDO::FETCH_ASSOC);
                $query4->closeCursor();

                foreach($row4 as $key => $value2)
                {
                    //print_r($value2);
                    echo $value2['event_id'].'========='.$value['event_id'];
                    if($value2['event_id'] == $value['event_id'])
                    {
                        echo " vous etes inscrit a cet evenement"."<br/><br/>";


                     }
                     else
                     {
                     ?>
                        <a href='#' class='event_register'>  s inscrire a l evenement</a><br/><br/>

and the result:

iiiii
12=========2 s inscrire a l evenement

Email: 
Nom: 
Prenom: 
Numero de telephone: 
Nombre de place que vous voulez reserver: 
13=========2 s inscrire a l evenement

Email: 
Nom: 
Prenom: 
Numero de telephone: 
Nombre de place que vous voulez reserver: 
18=========2 s inscrire a l evenement

Email: 
Nom: 
Prenom: 
Numero de telephone: 
Nombre de place que vous voulez reserver: 
oooooo
12=========12 vous etes inscrit a cet evenement

13=========12 s inscrire a l evenement

Email: 
Nom: 
Prenom: 
Numero de telephone: 
Nombre de place que vous voulez reserver: 
18=========12 s inscrire a l evenement`
A: 

you overwrite the $key in this line

foreach($row4 as $key => $value2)
Haim Evgi
`$key` is not been using
Sadat
A: 

You can use a break; to stop the foreach loop after you've got what you want.

Also, doing sql queries in a loop is not going to be fast, consider using something like "SELECT * FROM account_event WHERE account_id IN (ids)

Jochen