PDA

View Full Version : confusion over match of session and hash data


bazz
08-08-2008, 06:43 PM
Hi,

Doing my head in here, again. :(

I have a hash stored in the session.


'params' => {
'Pillowsone' => 'yes',
'Flowersone' => 'yes',
'number_of_children' => '1',
'Pillows' => 'Non-Allergenic Pillow',
'submit' => 'Continue with Booking',
'Flowers' => 'Bouquet in a Vase',
'number_of_adults' => '1'
},




I have retrieved data from a db table. (It can either be in a hash or an array) , currently highlighted red (below).

I (think), I need to match the hash keys with the first db value and, based on that conditional, output the values from the hash with the other two db-retrieved values.

the only relevant hash keys are Pillows and Flowers. and these are the values of the option_category as retrieved from the table. There may be others later but I want to understand the code, firstly.


I want to output this way


<td>$option_category</td><td>$option_name</td><td>$option_costs</td>



Surely there is a simpler way to begin this?


my $sth = $bookings_db_connect->prepare ("SELECT
O.option_category,
O.option_name,
O.option_cost
FROM
tbl_room_options O
where O.business_id = ?
")or die "prepare statement failed: $DBI::errstr\n";

$sth->execute($business_id);

my $option;
my $option_category;
my %params = % {$session->param('params') };


while ( $option = $sth->fetchrow_hashref )
{
$option_category = $option->{option_category};
my $option_name = $option->{option_name};
my $option_cost = $option->{option_cost};

while (my ($key, $value) = each(%params))
{

if ($key eq "$option_category"){
print qq( $key<br />
);
}
}
}



bazz