calmchess Posted July 2, 2010 Share Posted July 2, 2010 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 ); } } Link to comment https://forums.phpfreaks.com/topic/206584-stop-for-loop-when-if-statement-executes/ Share on other sites More sharing options...
AbraCadaver Posted July 3, 2010 Share Posted July 3, 2010 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; } } Link to comment https://forums.phpfreaks.com/topic/206584-stop-for-loop-when-if-statement-executes/#findComment-1080518 Share on other sites More sharing options...
calmchess Posted July 3, 2010 Author Share Posted July 3, 2010 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 Link to comment https://forums.phpfreaks.com/topic/206584-stop-for-loop-when-if-statement-executes/#findComment-1080524 Share on other sites More sharing options...
AbraCadaver Posted July 3, 2010 Share Posted July 3, 2010 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? Link to comment https://forums.phpfreaks.com/topic/206584-stop-for-loop-when-if-statement-executes/#findComment-1080530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.