Guest 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 Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/ Share on other sites More sharing options...
Guest Posted April 10, 2008 Share Posted April 10, 2008 help plz? Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513615 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, Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513624 Share on other sites More sharing options...
Guest Posted April 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513637 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 Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513654 Share on other sites More sharing options...
Guest Posted April 10, 2008 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";} Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513659 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); Link to comment https://forums.phpfreaks.com/topic/100427-need-help-with-serialize-again/#findComment-513673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.