$public_prod_id = 'C'.rand(1000000000,9999999999);
$_SESSION['public_prod_id'] = $public_prod_id;
$exist = mysqli_num_rows($pdo->query(
"SELECT * FROM `product`
WHERE `public_prod_id` = '{$_SESSION['public_prod_id']}' "
));
if($exist == 0){
$pdo->query(
"INSERT INTO ``
(
``
)
VALUES
(
'{}'
)
"
);
}
如果找到的結果是大於0
那我如何回到上面再產生一組新的號碼,然後再重新走一次?
do {
$public_prod_id = 'C'.rand(1000000000,9999999999);
$_SESSION['public_prod_id'] = $public_prod_id;
$exist = mysqli_num_rows($pdo->query(
"SELECT * FROM `product`
WHERE `public_prod_id` = '{$_SESSION['public_prod_id']}' "
));
} while ($exist > 0);