in reply to Re^3: Foreach Problem! Help!!!
in thread Foreach Problem! Help!!!

The $order value is there only to say what SQL Query to run when user clicks on a button, the program prints a table with values and it has a button to select everything by alphabetic order that's when I am passing the value to $order.
My question is to find out why the code doesn't work because of the first foreach loop on this line
foreach my $key_expal (%expal) {...

Where I need to extract the value of $key_expal to run the SQL query on the database.

Replies are listed 'Best First'.
Re*: Foreach Problem! Help!!!
by Roy Johnson (Monsignor) on May 25, 2004 at 19:31 UTC
    Your results do not come out in the order you expect because you are doing multiple queries in arbitrary order. You are doing one query for each value in %expal.

    It is not the same thing to do this:

    SELECT * FROM foo WHERE expal = 5 ORDER BY expal; SELECT * FROM foo WHERE expal = 3 ORDER BY expal; SELECT * FROM foo WHERE expal = 2 ORDER BY expal; SELECT * FROM foo WHERE expal = 4 ORDER BY expal; SELECT * FROM foo WHERE expal = 1 ORDER BY expal;
    as it is to do
    SELECT * FROM foo WHERE expal IN (5,3,2,4,1) ORDER BY expal;
    Your code is effectively doing the former. You seem to want it to do the latter.

    The PerlMonk tr/// Advocate