The way it looks now... your doing a while loop that will keep looping until unique is true. If unique never gets set to true, then it's going to loop forever. I don't see a need for that while loop. You can just do

$unique=checkDuplicate($newTeam);

also... your function could be simplified a little bit:

function checkDuplicate($value){
   global $teams;
   //do query here, return an array
   for($i=0; $i<count($teams); $i++){
       if($value==$teams[$i]){
           return true;
           }
       }
   return false;
   }

Be sure to escape the contents of $newTeam before doing anything like inserting it into a database or echoing it on the page.

Good luck!
-Rob



Randal Rust wrote:
I have always had trouble with trying to write these from scratch. The
code below is essentially what I have been working on, but it never
stops looping. What am I missing here?

<?php

$teams=array(
'Reds',
'Browns',
'Bengals',
'Cavaliers',
'Blue Jackets',
'Indians'
);

$unique=false;
$newTeam=$_POST['newTeam'];

function checkDuplicate($value){
    global $teams;
    $count=0;
    //do query here, return an array
    for($i=0; $i<count($teams); $i++){
        if($value==$teams[$i]){
            $count++;
            }
        }
    if($count == 0){
        //no matches
        return true;
        }
    else {
        //there are matches
        return false;
        }
    }
while(!$unique){
    $check=checkDuplicate($newTeam);
    if($check){ $unique=true; } else { $unique=false; }
    }

?>


_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to