in reply to Foreach Problem! Help!!!
You should be using placeholders for your variables. Something like:
Because %expal is a hash, your queries will be run in arbitrary order, but the results of each query should be returned in the order your query specified.$sql =<<"SELECT * FROM tbl_admin WHERE day = '$d' AND month = '$m_num' + AND year = '$y' AND expal = '?' AND status= '2'"; if($order == 2 ) { $sql .= " ORDER BY c_name"; } elsif ($order == 3 ) { $sql .= " ORDER BY expal"; } $sth = $dbh->prepare($sql); foreach my $key_expal (keys %expal) { $sth->execute($key_expal) || die $sth->errstr; while ($pointer = $sth->fetchrow_hashref) { my $expalnum = $pointer->{'expal'}; my $comp = $pointer->{'c_name'}; my $cltime = $pointer->{'time'}; my $cltime2 = $pointer->{'time2'}; my $last_name = $pointer->{'last_name'}; my $clnum = $pointer->{'c_number'}; my $status = $pointer->{'status'}; print "<br>L 265 - <b>$comp</b> $expalnum"; } }
Ordering by expal is redundant, though, when you're specifying that only one expal is acceptable. You might need to rethink your query. Do you really want to use an IN:
and no outer loop?$sql = "SELECT * FROM tbl_admin WHERE day = '$d' AND month = '$m_num' +and year = '$y' AND expal IN (".join(',',keys %expal).") AND status= +'2'";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Foreach Problem! Help!!!
by Anonymous Monk on May 25, 2004 at 18:58 UTC | |
|
Re: Re: Foreach Problem! Help!!!
by Anonymous Monk on May 25, 2004 at 17:32 UTC | |
by Roy Johnson (Monsignor) on May 25, 2004 at 18:25 UTC | |
by Anonymous Monk on May 25, 2004 at 18:57 UTC | |
by Roy Johnson (Monsignor) on May 25, 2004 at 19:31 UTC | |
by Anonymous Monk on May 25, 2004 at 17:43 UTC |