Jump to content

stop for loop when if statement executes


calmchess

Recommended Posts

The following for loop executes and performs an action via an IF statement the problem is if there are duplicate entries they also get deleted....i need to stop the for loop as soon at the if stament fires oneTime to preserve the duplicates.....and no i can say unique key to the database the duplicates need to exsist. Plz help.

 

for($i=0;$i<count($arr0);$i++){
$arr1=explode(":",$arr0[$i]);
if($arr1[0]==$_POST['uname']){
array_splice($arr0,$i,1);

$ser_arr0 = serialize($arr0);
$sql1 = "update yahvid.tracku set serdata='$ser_arr0' where modname='$_POST[modname'";
$retval1 = mysql_query( $sql1, $conn );

}
}

I'm not sure what your code is doing but to get out of a loop use break.

 

for($i=0;$i<count($arr0);$i++){
   $arr1=explode(":",$arr0[$i]);

   if($arr1[0]==$_POST['uname']){
      array_splice($arr0,$i,1);
      $ser_arr0 = serialize($arr0);
      $sql1 = "update yahvid.tracku set serdata='$ser_arr0' where modname='$_POST[modname]'";
      $retval1 = mysql_query( $sql1, $conn );
      break;
   }
}

my code grabs a seialized array out of a database then unserializes it explodes the array into fragments splices an index out based on some post variable....reserialzes it and puts it back in the database.......you can't see the entire script but you can see the important part

my code grabs a seialized array out of a database then unserializes it explodes the array into fragments splices an index out based on some post variable....reserialzes it and puts it back in the database.......you can't see the entire script but you can see the important part

 

OK and break works or no?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.