Re: Nested foreach statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



foreach($_POST['reporton_company'] as $cmp_ind =>$arrayd_cmp_id) {
        foreach($_POST['report_period'] as $rep_ind =>$arrayd_per_id) {
                foreach($_POST['questions_groups'] as $group_ind => $arrayd_group_no) {
                        mysql_select_db($database_name, $dname);

Why do that here? That's going to do it for each element in the
arrays, lots of overhead!

Move that outside the first loop.

I'd probably leave it as it is and make sure your data is what you
expect, ie use mysql_real_escape_string in appropriate places.

You could clean up one loop by doing this:

$query_get_list_of_answers = "SELECT * FROM answers LEFT JOIN
(questions, period) ON (questions.id=answers.ans_l_question_id AND
period.per_id=ans_l_period_id) where ans_l_company_id =
'$arrayd_cmp_id' AND per_id = '$arrayd_per_id' AND group_no IN (" .
implode(',', $_POST['questions_groups']) . ")";

but if I can enter dodgy values in the questions_groups form field,
you're hosed.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux