Query in loops

Funny or strange mistakes in coding.
User avatar
RMcGirr83
Past Contributor
Past Contributor
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Query in loops

Postby RMcGirr83 » 17 Feb 2011, 20:18

Holy....

Code: Select all

            $sql = 'SELECT *
                  FROM ' . POLL_OPTIONS_TABLE . "
                  WHERE topic_id = " . (int) $topic_id;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result))
            {
               $sql2 = 'SELECT *
                     FROM ' . POLL_VOTES_TABLE . "
                     WHERE poll_option_id = " . $row['poll_option_id'] . "
                        AND topic_id = " . $topic_id;
               $result2 = $db->sql_query($sql2);
               $voted_users = '';
               while ($row2 = $db->sql_fetchrow($result2))
               {
                  $sql3 = 'SELECT user_id, username, user_colour
                        FROM ' . USERS_TABLE . "
                        WHERE user_id = " . $row2['vote_user_id'];
                  $result3 = $db->sql_query($sql3);
                  $row3 = $db->sql_fetchrow($result3);
                  $voted_users .= get_username_string('full', $row3['user_id'], $row3['username'], $row3['user_colour']) . ' (' . $row2['vote_user_ip'] . ') ';
                  $db->sql_freeresult($result3);
               }
               $db->sql_freeresult($result2);


:shock:

Erik Frèrejean
New member
New member
Posts: 2
Joined: 06 Jun 2008, 14:54
Real name: Erik
Location: USERS_TABLE

Re: Query in loops

Postby Erik Frèrejean » 17 Feb 2011, 22:09

That's no coding fail, thats epic. How much did you drink to come up with such awesome code :beer:

User avatar
RMcGirr83
Past Contributor
Past Contributor
Posts: 6243
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: Query in loops

Postby RMcGirr83 » 17 Feb 2011, 22:28

Apparently not nearly enough. ;)

:beer:


Return to “Coding fails!”

Who is online

Users browsing this forum: CommonCrawl [Bot] and 0 guests