Hello I'm currently trying to create a page based on a database under mysql that would update itself for a client. However what I'm trying to do loops and returns the first value of the database each time and indefinetely when I want it to go on to another object in the database. Here is the code, I'm a beginner so the error might be flagrant, thanks for the help.
<?php
    
try
    {
        $db = new PDO('mysql:host=localhost;dbname=labase', 'root' ,'');
        $db->exec(" SET CHARACTER SET utf8 ");
        $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    catch(Exception $e){
            
        echo'une erreur est survenue';
        die();
            
    }
    
for ($i = 1; $i < 10; $i++) {
    if ($i=1){
        $select = $db->prepare("Select profession from contact where affiliation='nord' group by profession"); // je récupère les professions de la bdd
        $select->execute();
    }
    $data = $select->fetch(PDO::FETCH_OBJ);
    $profess=$data->profession; // je prends la prochaine profession
    
    $selectionner = $db->prepare("Select nomcontact, count(*) as nbrcontact from contact where affiliation='nord' and profession='$profess'"); // je prends les contacts qui ont cette profession ainsi que leur nombre
    $selectionner->execute();
    
    $prendre = $selectionner->fetch(PDO::FETCH_OBJ);
    $nbrcontact=$prendre->nbrcontact;// je récupère leur nombre
echo $profess;
echo $nbrcontact;
}
    
    ?>
 
     
     
     
    