bazz
04-18-2009, 01:42 AM
Hi,
I am calling a MySQL table query from a child sub, into a parent sub to use as a hash. I want to compare the hash values with those in an array and if they match, output one thing and if they don;t to output another. The has returns '1' instead of as string and I need you help on fixing it.
show_menus {
my @list_of_available_menus = get_available_menus($business_id,$business_name,$connect);
my %live_menus = get_live_menus($business_id,$business_name,$connect);
foreach my $key ( sort @list_of_available_menus )
{
print qq( lmk = $live_menus{$key} ); # busted
if ( $key ne $live_menus{$key} )
{
print qq(
<tr>
<td>
<input class="checkBox_inactiveMenu" type="checkbox" name="menuName" value="$key" />
</td>
<td><a href="$Request/$key">$key</a>
</td>
</tr>
);
}
else
{
print qq(
<tr>
<td>
<input class="checkBox_activeMenu" type="checkbox" name="menuName" value="$menuName" checked="checked" />
</td>
<td><a href="$Request/$key">$key</a>
</td>
</tr>
);
}
}
}
sub get_live_menus {
my ($business_id,$business_name,$connect) = @_;
my %live_menus;
my $sth = $connect->prepare("select
dm.menu_name
from
dishes_menus dm
where dm.live_from <= curdate()
and business_id = ?
") or die "prepare statement failed: $DBI::errstr\n";
$sth->execute($business_id);
while ( my @cols = $sth->fetchrow_array) {
$live_menus{$cols[0]}++;
}
print Dumper %live_menus;
return %live_menus;
}
Dumper shows this:
$VAR1 = 'Starters'; $VAR2 = { '' => 1 };
Please can anyone tell me what I am missing?
bazz
I am calling a MySQL table query from a child sub, into a parent sub to use as a hash. I want to compare the hash values with those in an array and if they match, output one thing and if they don;t to output another. The has returns '1' instead of as string and I need you help on fixing it.
show_menus {
my @list_of_available_menus = get_available_menus($business_id,$business_name,$connect);
my %live_menus = get_live_menus($business_id,$business_name,$connect);
foreach my $key ( sort @list_of_available_menus )
{
print qq( lmk = $live_menus{$key} ); # busted
if ( $key ne $live_menus{$key} )
{
print qq(
<tr>
<td>
<input class="checkBox_inactiveMenu" type="checkbox" name="menuName" value="$key" />
</td>
<td><a href="$Request/$key">$key</a>
</td>
</tr>
);
}
else
{
print qq(
<tr>
<td>
<input class="checkBox_activeMenu" type="checkbox" name="menuName" value="$menuName" checked="checked" />
</td>
<td><a href="$Request/$key">$key</a>
</td>
</tr>
);
}
}
}
sub get_live_menus {
my ($business_id,$business_name,$connect) = @_;
my %live_menus;
my $sth = $connect->prepare("select
dm.menu_name
from
dishes_menus dm
where dm.live_from <= curdate()
and business_id = ?
") or die "prepare statement failed: $DBI::errstr\n";
$sth->execute($business_id);
while ( my @cols = $sth->fetchrow_array) {
$live_menus{$cols[0]}++;
}
print Dumper %live_menus;
return %live_menus;
}
Dumper shows this:
$VAR1 = 'Starters'; $VAR2 = { '' => 1 };
Please can anyone tell me what I am missing?
bazz