vendredi 7 mai 2021

Generating random ref_id in PHP?

i want to create different ref_id for each users. i tried it with using str_shuffle function. it generates but when i refresh the page it changes. also, it generates the same ref_id for every user. Here are my codes:**

$users = $db->get_results("SELECT * FROM users");
if($users ){
  foreach($users as $u){
    $str = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPUQRSTUVWXYZ';
    $str_r = substr(str_shuffle($str), 0, 30);
    $ref_id=$db->query("UPDATE users SET ref_id= '$str_r'") ;
    echo "ref_id: $u->ref_id; ";
    echo '<br';
  }
}

i think i must use while but i didnt get any result. How can i fix this?**




Aucun commentaire:

Enregistrer un commentaire