[RESOLVED]How to process a ForEach Loop within a FOREACH loop

I need to show the response of a user to existing user comments

Heres what am trying to do..

@foreach(var d in notes){
   var replynote=db.Query("select Fname,ProfilePic,Feeds.FeedID,Note.noteID,ReplyNote.* from ReplyNote inner join userprofile on userprofile.userid=replynote.replyid  inner join feeds on feeds.feedid=replynote.replyid inner join Note on Note.noteid=replynote.replyid Where Feeds.FeedID=@0 and Note.noteid=@1",published.FeedID,d.noteID);

          <div class=" col-xs-2 right" style="float: left! important">
                            <img src="~/img/@d.ProfilePic" class="liked-this-iconys" alt="@d.Fname"  style="float: left! important">
                        </div>
                        <div class="col-xs-10"style="">
                        <div class="notesAuthor">@d.Fname<span class="notesContent">&nbsp;&nbsp;@String.Format("{0:MMM.dd}", d.noteTime)</span> </div>
<div class="notesContent">@Html.Raw(d.note)</div>  
                           foreach(var e in replynote){
                               <div class="notesReply">
          <div class=" col-xs-2 right" style="float: left! important">
                            <img src="~/img/@e.ProfilePic" class="liked-this-iconys" alt="@e.Fname"  style="float: left! important">
                        </div>
                        <div class="col-xs-10"style="">
                        <div class="notesAuthor">@e.Fname<span class="notesContent">&nbsp;&nbsp;@String.Format("{0:MMM.dd}", e.noteTime)</span> </div>
<div class="notesContent">@Html.Raw(e.note)</div>                                  
                                 
                   
                    
                    
                    </div>
                </div>    
                    } 
                    
                    </div>
                }

The problem is I do not get errors from the front-end, but I do not get the expected result either, it gets tiring...

Thanks

It would be helpful to anyone trying to help you if you were to:

(1)  Show your table structures that are involved

(2) Describe in plain terminology what it was that you WERE expecting

(3)  Put some line feeds in your code

Best I can tell is your join is assuming that all the ids are equal to reply id

from ReplyNote 
inner join userprofile 
        on userprofile.userid=replynote.replyid  
inner join feeds 
        on feeds.feedid=replynote.replyid 
inner join Note 
           on Note.noteid=replynote.replyid 

What that join is saying is:

(1)  Every reply is identified by exactly one replyId

(2) Each reply has 0, 1, or more userProfiles

(3)  Each reply has 0, one, or more Feeds

(4) Each reply has 0, one, or more Notes

(5) Each UserProfile can have at most one reply

(6) Each Feed can have at most one reply

(7) each Note can have at most one reply

I suspect that is not what you wanted to be the case

noteID          note                                                                    noteTime                                    UserID FeedID

2 Welcome to Tradecraft,  ☺ 11/28/2014 10:09:43 PM 3 19
3 Ahhh you’re a writer.. . 11/28/2014 10:55:50 PM 3 19
         

replyID    replyNote              NoteID        replyTime                                                              UserID   FeedID

1 Hello 2 11/28/2014 10:41:58 PM 3 19
2 Welcome 2 11/28/2014 11:49:53 PM 3 19
           

Am designing a Comment System, where a User(UserID) Comments on an open Story(FeedID), IT gets stored in the first table (Note), if another user decides not to insert a new comment but reply to an existing comment, it gets populated into table2 (ReplyNote)
with the NoteID(FK) the UserID of the user replying to an existing comment and the Article where this is taking place from (FeedID).

I Want to achieve a chronological order of the comment system. For example,

   John Doe Nov.30

   Wishing you a big thank you if you solve this problem for me

                                                      Janet Doe Nov.31

                                                       @John, Don’t mention, I would send you a new post

   Fred Doe Nov.30

   This article is a blessing in disguise, probably solved some issues.

The First foreach loop shows only (John Doe and Fred Doe post) the second foreachloop ought to show Janet Doe post, but its not showing it, and it is not returning any errors too.

I think the problem is largely due to my select statement,

I have tested it via sql manager and it returned null

I changed the parameters and its working well

select Fname,ProfilePic,Feeds.FeedID,Note.noteID,ReplyNote.* from ReplyNote 
left join userprofile on userprofile.userid=replynote.userid  
left join feeds on feeds.feedid=replynote.feedid 
left join Note on Note.noteid=replynote.noteid 
 
Where Feeds.FeedID='19' and Note.noteid='2'

This returned accurate answers.. Lemme go and implement this

Leave a Reply