在我的网站上,用户可以更新和其他可更新,像往常一样像其他社交网站评论..编写更好的代码/查询
什么我做:
query = fetches first name, last name, user id, update id, update post UNION same details for the user who has logged in i.e /* Updates Of Current Logged In User + Updates Of People He Is Following */
loop {
prints first name last name and update
}
后来我介绍了评论功能所以现在我要做的就是在循环中我称之为查询并再次征求意见运行一个循环..
loop {
prints first name last name and update
commentquery = fetches firstname, last name, user id, comment, of the particulat post
again loop {
prints first/last name of the person who commented, and his comment
}
}
现在根据我我想这可以用SQL查询来完成,当我检索帖子时,我可以随它一起获取评论,或者这是正确的方式?问题是当外部循环运行时,内部循环也会运行以获取适当的注释,那么我可以连接表来检索与帖子/更新相关的注释吗?
给出代码,而不是描述为你的代码 – Gautam3164
我没有要求修复我的代码,我只是想知道在循环中调用查询的逻辑是错误的,所以我可以将它与外部循环连接起来更新循环,并可以获取与帖子相关的评论/更新 –
如果您只需要一个查询,则可以选择用户与帖子以及评论表之间的联接。不,在循环中查询并不差 - 这完全取决于您的效率指标。如果您的编码时间比几毫秒的执行时间更值得,请使用易于理解和维护的代码模型。 –