I have a simple code here:
$rand = mt_rand(100000, 999999);
$sid = array(
":sponsorID" => $rand
);
$accounts = $db->select("accounts", "sponsorID = :sponsorID", $sid);
while (count($accounts) > 0) {
$new = mt_rand(100000, 999999);
}
echo $new;
What it basically does is to check if the generated number from $rand is already in the database and will set a $new variable. My problem is when I echo out $new, I always get an undefined index of that variable. How can I call that variable outside the while loop?
$newin all iterations? I assume you want to add abreakorcontinuestatement to that loop... Also: this will be an endless loop once there is an entry in the database, since you do not modify$accountsinside the loop...foror aforeachloop instead of that while...