Loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Loop

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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();
   }
}
Post Reply