For juntamante with the while

Asked

Viewed 52 times

1

Hi, I’m creating a fb BOT and I need help, I need that together with the while of the database I need a for that goes from 1 to the last record. So the user can send the code corresponding to the registration!

}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!");                              
}
  • Where exactly the for would enter there in this code? And the function of while isn’t just going through all the records? If yes, what would be the function of the for?

  • I create the for this: 1 - Title 1; 2 - Title2; but the titles come from the database; the numbering create that came from the for

  • And what the while is currently doing?

  • Currently as this in the above code posted, it is to list all titles but without numbering

  • So what you need is not a for, but only one counter for the securities?

  • yes, and how could I do that?

Show 1 more comment

1 answer

0


If the intention is just to insert the numbering together with the title, just set an auxiliary counter and interpolate:

$contador = 1;

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

Thus, $titulo will be something like:

  • 1 - Title A
  • 2 - Title B
  • ...
  • That’s exactly what I was looking for, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.