php - counter ID number instead of random ID number? -
good day, have problem , dont know how counting id number instead of random numbers, please me. thank you. codes working on random id, want in counting number id. thanks
<?php $hostname_conn = "localhost"; $database_conn = "user_id"; $username_conn = "root"; $password_conn = ""; $conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),e_user_error); mysql_select_db($database_conn,$conn); // run endless loop while(1) { $randomnumber = mt_rand(10, 100);// generate unique random number $query = "select * tblrand the_number='".mysql_real_escape_string ($randomnumber)."'"; // check if exists in database $res =mysql_query($query,$conn); $rowcount = mysql_num_rows($res); $id=$randomnumber; // if not found in db (it unique), insert unique number data_base , break out of loop if($rowcount < 1) { $con = mysql_connect ("localhost","root"); mysql_select_db("user_id", $con); $sql = "insert tblrand(the_number) values('".$randomnumber."')"; mysql_query ($sql,$con); mysql_close ($con); break; } } echo "it-form" .$id; ?>
Comments
Post a Comment