I have create a generate random in php and insert into mysql already. But I want to loop it 1000 times when I refresh for one time. All item must go to store in database. How can I do this?
function generateCode($length = 11) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
echo $lucky_code=generateCode()."<br/>";
$servername = "localhost";
$username = "root";
$password = "";
$database = "random";
$cnt = mysql_pconnect($servername, $username, $password) or die(mysql_error());
mysql_select_db($database);
mysql_query("INSERT INTO tbl_code(code) VALUES('$lucky_code')",$cnt) or die(mysql_error());