Jump to content

splice problem


calmchess

Recommended Posts

I need the following function to  get a serialzed array from the database explode strings from the resulting arrays......then splice out 1 index reserialze the new array and put it back in the database.......now the below function does just that the problem is for some reason its splicing out 2 indexes...I also need to preserve duplicates i only want to remove 1 index...i've echoed till my fingers bleed and cannot find the reason.......PLZ help me debug this script.

 

<?php session_start();
include("../secure_php/mod_database.php");

$sql = "select serdata from yahvid.tracku where modname='$_POST[modname]'";
$retval = mysql_query( $sql, $conn );
$row = mysql_fetch_array($retval);

$arr0= unserialize($row['serdata']);
$_SESSION['test0']=$arr0;   

for($i=0;$i<count($arr0);$i++){
$arr1=explode(":",$arr0[$i]);
if($arr1[0]==$_POST['uname']){
$new_arr0 = array_splice($arr0,$i,1);
$ser_arr0 = serialize($arr0);
$_SESSION['test1'] =$ser_arr0;
$sql1 = "update yahvid.tracku set serdata='$ser_arr0' where modname='$_POST[modname]'";
$retval1 = mysql_query( $sql1, $conn );
break;
}
}
echo "success=success";
?>

Link to comment
https://forums.phpfreaks.com/topic/206634-splice-problem/
Share on other sites

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.