For joining with while

1

Hello, I am creating a BOT of fb and I need help, I need that along with the while of the database I need a for going from 1 to the last record. For the user to be able to send the corresponding code to the registry!

}elseif($text == "BONUS"){
$id_cl = $resexiste->id;                            
$existebonus = BD::conn()->prepare("SELECT * FROM 'bonus_attr' WHERE user_id = ? AND usado = ? ORDER by bonus_id desc");
$existebonus->execute(array($id_cl, "0"));
if($existebonus->rowCount() == 0){
    enviaMSG($sender, "Não ha nenhum bonus atribuido a esta conta!");                               
}else{
    enviaMSG($sender, "Envia o codigo correspondente ao bónus que queres usar:");
    while($reseb = $existebonus->fetchObject()){
        $titulo = $reseb->bonus_title;
        enviaMSG($sender, $titulo);
    }
}
}else{
    enviaMSG($sender, "Syntax Invalida!");                              
}
    
asked by anonymous 11.06.2018 / 11:23

1 answer

0

If the intention is just to insert the numbering together with the title, simply define an auxiliary counter and do the interpolation:

$contador = 1;

while($reseb = $existebonus->fetchObject()){
    $titulo = "{$contador} - {$reseb->bonus_title}";
    enviaMSG($sender, $titulo);
    $contador++;
}

So, $titulo will be something like:

  • 1 - Title A
  • 2 - Title B
  • ...
11.06.2018 / 14:29