Page 1 of 1

Loop

Posted: Sat Jul 17, 2004 11:48 am
by ddragas
Hi all!

I've got function "function assign_rand_value" that makes random ID wich is primary key. I was interested in making loop with database to make primary key that is not already in database

I know it goes with "while" but don't know how to make it with database.

Please if somebedy can help me or give me right direction in tutoral

Posted: Sat Jul 17, 2004 12:46 pm
by kettle_drum

Code: Select all

function blah(){
   $key = make_your key here
   
   $result = mysql_query("SELECT count(id) FROM table WHERE id = '$key'");
   $result = mysql_fetch_array($result);
   if(!$result['count(id)']){
      return $key;
   }else{
      blah();
   }
}