i'm new in php. i just want to generate random names (or what you want...). it does works! but when i put in the middle of the code one "do/while" to control and avoid duplicates names it DOES NOT WORKS.... why? what's wrog with my code? i'm exhauste, destroyed.
<?php
require_once 'config.php';
require_once 'dbconn.php';
function getnome() {
$nome = ['tin', 'pin', 'nid', 'din', 'vin'];
return $nome[mt_rand(0, count($nome) - 1)];
}
for ($f =0; $f<6; $f++) {
$arr = [];
do {
$x = getnome();
}
while (in_array($x, $arr));
$arr[]=$x;
$query = "INSERT INTO ants (ant_id, nome) VALUES (NULL, '".getnome()."')";
$res = $mysqli->query($query);
if (!$res) {
echo('<br>Error' . $mysqli->error);
} else {
echo $mysqli->affected_rows . ' created';
}
}
?>