Gossamer Forum
Home : General : Databases and SQL :

insert hash into db

Quote Reply
insert hash into db
HI seniro


I try to insert partial of cookie into the column orderdetail , unfortunately it seems i am doing something wong

Could someone here help me a bit?

Many thanks.



my $cgi = new GT::CGI;
my $session = new CGI::Session(undef, $cgi, {Directory=>'c:/tmp/carttmp'});
my @partofcookie= @{$session->param('CART')};
$tab->insert( #######
{

ID => '2merchantID@merchantID.com' ,
orderdate => \"now()" ,
orderdetail => "@partofcookie" ,
Sname => '2testname' ,
Semail => 'test@test.com'
} )##############ended



After inserting colum of orderdetail show somethiinglike this (HASH(0x1c30450))
Quote Reply
Re: [courierb] insert hash into db In reply to
  


the @partofcookie look like this


{name => 'ddd',quantity => 6,price => '15',colour => 'red',size => 'xxl',itemID => 15},{quantity => '1',name => 'gmailoknow',price => '8',itemID => '34'}
Quote Reply
Re: [courierb] insert hash into db In reply to
If you want ALL the data from an array, you need something like:

orderdetail => join(" - ", @partofcookie"),

Otherwise, if you only want for example the color, you would use:

orderdetail => $partofcookie[3] ,

However, it looks like the value of the array is a hashref, so you probably need something like:

Code:
orderdetail => get_cookie_vals($partofcookie[0]),

..and then a function :

Code:
sub get_cookie_vals {

my $back;
map {
$back .= "$_ --> $_[0]->{$_} \n"
} keys %$_[0];

return $back;

}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] insert hash into db In reply to
thanks Andy

i have settled insert funcation now

it should be
my $partofcookie = $session->param("CART") || [];

then i check the db. it insert the data correctly.



now i need to try how to get the array from the column for using.

thanks
Quote Reply
Re: [courierb] insert hash into db In reply to
Hi,

Ok NP - so what does the format look like in the DB (so you can read it) ?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] insert hash into db In reply to
andy


it looks like this

{name => 'ddd',quantity => 6,price => '15',itemID => 15},{quantity => '1',name => 'gmailoknow',price => '8',itemID => '34'}

exactly the same as session cart looks like
Quote Reply
Re: [courierb] insert hash into db In reply to
MMm, not really sure how you would convert that into a usable data, sorry.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [courierb] insert hash into db In reply to
why i want the column looks like this
as i may try to add more key and value to it. let us say size. colour . weight........ it depends on the needs.
Quote Reply
Re: [courierb] insert hash into db In reply to
 here it is the code i used it before when i use the way of cgi::session::file



my @partofcookie= @{$session->param('CART')}; ### have to defined here or produce error:undefined value as an ARRAY reference
foreach my $product ( @partofcookie ) { ####tested ok sss

$product->{prod_subtotal} = $product->{price} * $product->{quantity};
$tags->{total_price} += $product->{prod_subtotal};
$tags->{itemmaxtemp}=$itemmaxtemp;
$tags->{itemID}=$itemID;
push @{$tags->{cart_loop}}, $product;
}

print $IN->header();
print Links::SiteHTML::display('8gtcart', $tags);
exit;
}


then it will print the correct cart content and total price.
Quote Reply
Re: [courierb] insert hash into db In reply to
but now i need to get data from mysql db and format it correctly for using
i still got headache on it.
Quote Reply
Re: [courierb] insert hash into db In reply to
output looks like this

Product ID Product Unit Price Qty Subtotal
1004 (product4name) 44 1 X 44
1002 (product2name) 22 1 X 22
1003 (product3name) 33 1 X 33


Total 99



X is a link when click it will delete this item from cart

Last edited by:

courierb: Jul 22, 2009, 5:43 AM