Hi Anthony,

I think that part is correct. Here is the return from my request:

correct_questions:
26:
answered_by:
1L
correct:
True
id:
26L
last_update:
datetime.datetime(2014, 10, 13, 19, 49, 6)
question:
5L
submitted:
Yes
35:
answered_by:
1L
correct:
True
id:
35L
last_update:
datetime.datetime(2014, 10, 13, 23, 6, 51)
question:
3L
submitted:
Yes
55:
answered_by:
1L
correct:
True
id:
55L
last_update:
datetime.datetime(2014, 10, 14, 17, 45, 4)
question:
7L
submitted:
William
58:
answered_by:
1L
correct:
True
id:
58L
last_update:
datetime.datetime(2014, 10, 14, 18, 20, 4)
question:
8L
submitted:
8
68:
answered_by:
1L
correct:
True
id:
68L
last_update:
datetime.datetime(2014, 10, 14, 22, 41, 33)
question:
10L
submitted:
262144
70:
answered_by:
1L
correct:
True
id:
70L
last_update:
datetime.datetime(2014, 10, 14, 22, 49, 52)
question:
1L
submitted:
Hello World
79:
answered_by:
1L
correct:
True
id:
79L
last_update:
datetime.datetime(2014, 10, 14, 22, 53, 36)
question:
11L
submitted:
Autumn
81:
answered_by:
1L
correct:
True
id:
81L
last_update:
datetime.datetime(2014, 10, 15, 4, 27, 28)
question:
9L
submitted:
4
85:
answered_by:
1L
correct:
True
id:
85L
last_update:
datetime.datetime(2014, 10, 15, 23, 6, 48)
question:
2L
submitted:
learning
Had to run the first for loop to get into the keys and then compared 
values. 

I've modified the code to do check if the question was answered correctly 
in the controller and append the question id to a list. Still not 
working... here is my controller:


def questions_for_people():
    correctList = []
    correct_questions = db((db.questions_answered.correct=="on") & 
(db.questions_answered.answered_by==auth.user.id)).select(db.questions_answered.ALL,
 
groupby=db.questions_answered.question, distinct=True).as_dict()
    for row in correct_questions:
        for item in all_questions:
            if correct_questions[row]['question'] == item['id']:
                correctList.append(int(item['id']))
    return dict(correctList=correctList)

and in my view:
            <ul>
                    {{for question in all_questions:}}
                    {{if question['diff_level']==100 and question['id'] not 
in correctList:}}
                
                    <li class="padded"><a href="{{=URL('challenges', 
vars={'chal':question['id']})}}">{{=question['title']}} 
({{=question['points']}} pts) </a></li>
                {{pass}}
                    {{else:}}
                {{if question['diff_level']==100 and question['id'] in 
correctList:}}
                <li class="padded"><i class="fa fa-check icon-small"></i> 
<a href="{{=URL('challenges', vars={'chal':question['id']})}}", 
style="color:gray;">{{=question['title']}} ({{=question['points']}} pts) 
</a></li>
                {{pass}}
                {{pass}}

when I run this nothing returns back to my menu... 

On Wednesday, October 15, 2014 7:44:46 PM UTC-4, Anthony wrote:
>
> The <a> element in the inner loop only references the question variable, 
> which is set in the outer loop. Perhaps instead of question, you meant to 
> put correct_questions[record]
>
> Anthony
>
> On Wednesday, October 15, 2014 7:03:39 PM UTC-4, LoveWeb2py wrote:
>>
>> Hello.... I'm trying to create a menu for users who have already answered 
>> a question correctly. The questions are stored in the database, but for 
>> some reason my double for loop displays 10 of the same question. When I try 
>> my logic using python web2py.py -S myapp -M the logic works fine, however 
>> when I transfer it to the view it shows something like this:
>>
>> Menu item 1
>> Menu item 1
>> Menu item 1
>> Menu item 1
>> Menu item 1
>> Menu item 1
>> Menu item 2
>> Menu item 2
>> Menu item 2
>> Menu item 2
>> Menu item 2
>>
>> and so on and so on... I'm guessing it has something to do with my for 
>> loop, but I've been stuck on this for hours. Any help would be greatly 
>> appreciated. Thanks!
>>
>>
>> code here:
>>
>>>             <ul>{{try:}}
>>>
>>>                     {{for question in all_questions:}}
>>>
>>>                 {{for record in correct_questions:}}
>>>
>>>                     {{if question['difficulty']=='subject1' and 
>>>> correct_questions[record]['question'] != question['id']:}}
>>>
>>>                     <li class="padded"><a href="{{=URL('challenges', 
>>>> vars={'chal':question['id']})}}">{{=question['title']}} 
>>>> ({{=question['points']}} pts) </a></li>
>>>
>>>                     {{pass}}
>>>
>>>                     {{pass}}
>>>
>>>                     {{else:}}
>>>
>>>                 
>>>
>>>                 <li class="padded"><i class="fa fa-check 
>>>> icon-small"></i> <a href="{{=URL('challenges', 
>>>> vars={'chal':question['id']})}}", 
>>>> style="color:gray;">{{=question['title']}} ({{=question['points']}} pts) 
>>>> </a></li>
>>>
>>>                 {{pass}}
>>>
>>>                     {{except:}}
>>>
>>>                 {{pass}}
>>>
>>>  
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to