Hi, I am beginner RoR. I need your advanced programming... @rollresults = RollResult.where(:banker_id =>''3'') ---------------------------- | banker_id | roll_no | ---------------------------- | 3 | 332 | ---------------------------- | 3 | 512 | <-- when roll_no match ''512'' ---------------------------- | 3 | 332 | -| ---------------------------- | 3 | 512 | > listing them 3 times ---------------------------- | 3 | 512 | -| ---------------------------- | 3 | 332 | ---------------------------- | 3 | 332 | ---------------------------- | 3 | 512 | <-- when roll_no match ''512'' ---------------------------- | 3 | 264 | -| ---------------------------- | 3 | 332 | > listing them 3 times ---------------------------- | 3 | 666 | -| ---------------------------- The output I want as below: ---------------------------- | banker_id | roll_no | ---------------------------- | 3 | 332 | ---------------------------- | 3 | 512 | ---------------------------- | 3 | 512 | ---------------------------- ---------------------------- | 3 | 264 | ---------------------------- | 3 | 332 | ---------------------------- | 3 | 666 | ---------------------------- Please help me... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jul-21 08:59 UTC
Re: matching roll_no then loop 3 times, next loop..
On Jul 21, 9:43 am, Joachim Cheng <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, I am beginner RoR. I need your advanced programming... > > @rollresults = RollResult.where(:banker_id =>''3'')So you want to group your results by roll_no ? Fred> ---------------------------- > | banker_id | roll_no | > ---------------------------- > | 3 | 332 | > ---------------------------- > | 3 | 512 | <-- when roll_no match ''512'' > ---------------------------- > | 3 | 332 | -| > ---------------------------- > | 3 | 512 | > listing them 3 times > ---------------------------- > | 3 | 512 | -| > ---------------------------- > | 3 | 332 | > ---------------------------- > | 3 | 332 | > ---------------------------- > | 3 | 512 | <-- when roll_no match ''512'' > ---------------------------- > | 3 | 264 | -| > ---------------------------- > | 3 | 332 | > listing them 3 times > ---------------------------- > | 3 | 666 | -| > ---------------------------- > > The output I want as below: > ---------------------------- > | banker_id | roll_no | > ---------------------------- > | 3 | 332 | > ---------------------------- > | 3 | 512 | > ---------------------------- > | 3 | 512 | > ---------------------------- > > ---------------------------- > | 3 | 264 | > ---------------------------- > | 3 | 332 | > ---------------------------- > | 3 | 666 | > ---------------------------- > > Please help me... > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #1012069:> On Jul 21, 9:43am, Joachim Cheng <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi, I am beginner RoR. I need your advanced programming... >> >> @rollresults = RollResult.where(:banker_id =>''3'') > > So you want to group your results by roll_no ? > > FredYes, I want to result group by roll_no. @rollresults = RollResult.where(:banker_id =>''3'') @rollresults.each do |p| if p.roll_no == ''512'' #<--- Can''t work # group by 3times.. else # continues finding roll_no == ''512'' end end Can you teach me...? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jul-21 13:45 UTC
Re: matching roll_no then loop 3 times, next loop..
On Jul 21, 11:08 am, Joachim Cheng <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #1012069: > > > On Jul 21, 9:43am, Joachim Cheng <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Hi, I am beginner RoR. I need your advanced programming... > > >> @rollresults = RollResult.where(:banker_id =>''3'') > > > So you want to group your results by roll_no ? > > > Fred > > Yes, I want to result group by roll_no. > > @rollresults = RollResult.where(:banker_id =>''3'') > @rollresults.each do |p| > if p.roll_no == ''512'' #<--- Can''t work > # group by 3times.. > else > # continues finding roll_no == ''512'' > end > end >I don''t understand what you mean by ''group by 3 times'', but you might want to look at group_by (method on array) or at sql''s "group by" clause Fred> Can you teach me...? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #1012126:> On Jul 21, 11:08am, Joachim Cheng <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> > I don''t understand what you mean by ''group by 3 times'', but you might > want to look at group_by (method on array) or at sql''s "group by" > clause > > FredEmm.. ok, I just want to look the loop. In the beginning, we searching the roll_no is equal to ''512''. Next collecting 3 steps, roll_no = [332, 512, 512], to output. After that, we searching the roll_no also equal to ''512''. Next collecting 3steps again, roll_no = [264, 332, 666], to output. Repeat the same method to find roll_no == ''512'', next collect 3steps and show them to output. Can you make it? Thank you. :D -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, everyone. I have solved this problem by myself. Thank you for Frederick Cheung guide me.. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.