Page 1 of 1
delete object from serialized data
Posted: Tue Aug 03, 2010 8:16 am
by koi_s3ng
Hi, I'm actually having some issue regarding serialization.. I'm able to save and update my database using serialized and unserialized, however I'm not able to delete data from this array..
May I know is there any solution to my doubt..
a:8:{i:0;s:6:"tset11";i:1;s:5:"test2";i:2;s:5:"tset3";i:3;s:6:"tset43";i:4;s:4:"test";i:5;s:0:"";i:6;s:4:"test";i:7;s:0:"";}
Cheers
koi_s3ng
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 9:43 am
by jraede
Unserialize, delete, serialize.
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 9:51 am
by koi_s3ng
Code: Select all
$Policy_No=$_GET["arrayno"]);
$query ="SELECT Policy_No FROM jos_receipt_items WHERE ReceiptNo =". $ReceiptNo ;
$result=mysql_query($query)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$Policy_No = unserialize($row["Policy_No"]);
foreach($Policy_No as $Policy_Nos => $Policy_Nos_value)
{
if($Policy_Nos == $arrayno)
{
$Policy_No[] = $Policy_Nos_value;
$query2 ="DELETE FROM jos_receipt_items WHERE ReceiptNo=". $ReceiptNo ." AND Policy_No='" . $Policy_Nos_value ."'";
$result2=mysql_query($query2)or die(mysql_error());
}
}
}
sorry if lets say i would like to remove the object from array position 3.. how to i go about doing it.. is my above syntax correct?
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 10:00 am
by jraede
Did you mean to say $arrayno = $_GET['arrayno'] in the first line? Otherwise you're setting a variable and then setting it to something else a few lines later, and then using an empty variable $arrayno in a check within the loop.
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 10:07 am
by koi_s3ng
yup.. sorry.. it was a typo.. but even if i changed it to $arrayno = $_GET["arrayno"] i'm still not getting any more..
if i echo out my query this is what i get..
DELETE FROM jos_receipt_items WHERE ReceiptNo=00003 AND Policy_No='tset11'
but when i check my database the object is still not removed..
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 10:14 am
by jraede
Try putting single quotes around the 0003
Re: delete object from serialized data
Posted: Tue Aug 03, 2010 10:49 am
by koi_s3ng
erm sorry.. even if i place single quote for 00003, its still not working.. but is my syntax in my earlier post correct??