0

I have the following row within a table:

<TR>
    <TD style="text-align:center;width:50px">{% for z in recentResultHistory %} {{ z.0 }} {% endfor %}</TD>
    <TD style="text-align:center;width:100px"></TD>
    <TD style="text-align:center;width:50px">V</TD>
    <TD style="text-align:center;width:100px"></TD>
    <TD style="text-align:center;width:50px">{% for z in recentResultHistory %} {{ z.0 }} {% endfor %}</TD>
</TR>

when the first instance of the {% for z in recentResultHistory %} {{ z.0 }} {% endfor %} runs I get the expected result. When it runs for the second time it produces no results like it is not looping at all. Do I need to reset the loop in some way?

The variable is created in my django view.py as follows:

        cursor = connection.cursor()

        cursor.execute("""
                        select
                        team,
                        group_concat( concat(result, '-', convert(opponent USING utf8), '-', team_score, '-', opponent_score, '-', mstatus)
                                     order by fixturedate desc
                                    separator '|') as output from plain_result
                        where (select count(*)
                               from plain_result as p
                               where plain_result.team = p.team
                               and p.fixturedate>=plain_result.fixturedate) <= 5
                        group by team
                       """)

        recentResultHistory = cursor.fetchall
Alan Tingey
  • 835
  • 11
  • 39

1 Answers1

0

I should be using list(cursor) rather than cursor.fetchall(). Daniel and dkasak gave me the inspiration to look and I found the following which solved my issue:

cursor.fetchall() vs list(cursor) in Python

Community
  • 1
  • 1
Alan Tingey
  • 835
  • 11
  • 39