Hi All
I've made two functions, One function checks whether the same reference no. exists and another function just generates part of reference no.
$ref = autoGR ();
$ref_no = $PCwho."-".$ref."-".$dor_ref;
$va = chkRef ($ref_no, 'tbl_test')
//I don't know what to do next from here, how should i go back to autoGR();
Once the autoGR(); has generated the $ref, i need to keep checking in the table whether there is no duplicate ref no. So if its same it needs to autoGR(); till its a unique one.
Please help me on this one, how i should do it?
function chkRef ($ref, $tableName)
{
$srquery = "select fld_ref from $tableName where fld_ref='$ref'";
$srresult = mysql_query($srquery) or die("Reference Check Failed");
if (mysql_num_rows($srresult) != 0) return $refv = 1;
else return $refv = 0;
}
function autoGR ()
{
srand(time());
$a="123456789";
for($i; $i<=6; $i++)
{
$ref.=substr($a, (rand()%(strlen($a))),1);
}
return $ref;
}