gdfhghjdfghgfhf Posted April 10, 2008 Share Posted April 10, 2008 here's what i'm trying to do i have a field in my database (options in table quebec_calendarcustomfield) used in vbulletin for calendar custom fields. I want to allow a group of users to add and delete fields... So now i'm trying to make a page where my users are able to delete a field. All fields are serialized and stored in quebec_calendarcustomfield WHERE calendarcustomfieldid = '1' so i tryed to unserialize it, do a str_replace to delete the field i want, and serialize it back.... but i'm stuck at serializing back, i can't find out how to serialize the whole array include("db.php"); $query = "SELECT options FROM quebec_calendarcustomfield WHERE calendarcustomfieldid = '1'"; $res = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($res)) { $a = $row["options"]; $unseri = unserialize($a); foreach($unseri as $value) { $hmm = str_replace("$legroupe", "", "$value"); echo $hmm; } echo "<br><br>"; $uhh = serialize($value); echo $uhh; $cc = mysql_real_escape_string($uhh); $zxc = "UPDATE quebec_calendarcustomfield SET options = '$uhh' WHERE calendarcustomfieldid = '1'"; $res = mysql_query($zxc) or die(mysql_error()); } $legroupe is a defined $_GET value and it contains the line i want to delete $a = $row["options"]; is the serialized array of ALL the fields, including the one i want to delete Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 10, 2008 Author Share Posted April 10, 2008 help plz? Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 you could use unset(); $unseri = unserialize($a); print_r($unseri); echo("<br />"); unset($unseri[$legroupe]); print_r($unseri); echo("<br />"); $uhh = serialize($unseri); print_r($uhh); hope this helps, Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 10, 2008 Author Share Posted April 10, 2008 hmmm it doesnt work for me, the thing to delete ($legroupe) is still here what is unset? it does the same thing i was doing with str_replace? btw, $legroupe is not serialized, but $a (row["options"]) is Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 give us the output source, what do $a look like? echo it out for us Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 10, 2008 Author Share Posted April 10, 2008 serialized version of $a: a:7:{i:1;s:18:"111111111111111111";i:2;s:18:"222222222222222222";i:3;s:13:"3333333333333";i:4;s:13:"4444444444444";i:5;s:14:"55555555555555";i:6;s:12:"666666666666";i:7;s:12:"777777777777";} Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 oh ok try this: $unseri = array_flip(unserialize($a)); unset($unseri[$legroupe]); $unseri = array_flip($unseri); $uhh = serialize($unseri); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.