delete object from serialized data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
koi_s3ng
Forum Newbie
Posts: 4
Joined: Tue Aug 03, 2010 8:12 am

delete object from serialized data

Post 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
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: delete object from serialized data

Post by jraede »

Unserialize, delete, serialize.
koi_s3ng
Forum Newbie
Posts: 4
Joined: Tue Aug 03, 2010 8:12 am

Re: delete object from serialized data

Post 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?
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: delete object from serialized data

Post 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.
koi_s3ng
Forum Newbie
Posts: 4
Joined: Tue Aug 03, 2010 8:12 am

Re: delete object from serialized data

Post 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..
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: delete object from serialized data

Post by jraede »

Try putting single quotes around the 0003
koi_s3ng
Forum Newbie
Posts: 4
Joined: Tue Aug 03, 2010 8:12 am

Re: delete object from serialized data

Post 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??
Post Reply