使用MYSQL和PHP循环出流后和相关注释(Loop out post stream and associated comments using MYSQL and PHP)
我知道之前已经问了几次,但我已经尝试了这个网站上的所有答案,但我仍然没有在哪里。
我正在尝试创建一个Twitter类型的订阅源,它将循环播出帖子,然后为订阅源中的每个帖子循环出相关的评论(类似于Facebook)。 我不确定执行此操作的最佳方法是两个单独的查询还是一个查询中的所有查询以及如何将其全部循环?
我的数据库结构如下:
--TWEETS-- --COMMENTS-- --USERS-- id id id accountno accountno accountno userid userid email createdat createdat name tweet tweetid image comment
我的PHP函数如下:
function gettweets(){ $result = mysql_query("SELECT tweets.id,tweets.tweet,tweets.createdat,tweets.userid,users.name,users.avatar,users.biog FROM tweets INNER JOIN users ON tweets.userid = users.id WHERE tweets.accountno ='123456' ORDER by tweets.ID DESC LIMIT 20"); while($row = mysql_fetch_array( $result )) { $name = $row['name']; $biog = $row['biog']; $avatar = $row['avatar']; $newtweet= $row['tweet']; $tweetid = $row['id']; $timeago = ago($row['createdat']); $thistweet = ''; $thistweet .= "<div class='tweet' data-tweetid='$tweetid'>"; $thistweet .= "<div class='left'>"; $thistweet .= "<img width='45' height='45' src='$avatar' alt='placeholder+image'>"; $thistweet .= "</div><!-- / -->"; $thistweet .= "<div class='right'>"; $thistweet .= "<span class='name'>$name says</span>"; $thistweet .= "<p>"; $thistweet .= "$newtweet"; $thistweet .= "</p>"; $thistweet .= "<span class='replybar'> $timeago <a class='like' data-tweetid='$tweetid' href='' title=''>Like</a> | "; $thistweet .= "<a class='favourite' data-tweetid='$tweetid' href='' title=''>Favourite</a> | "; $thistweet .= "<a class='mainreply' href='' title=''>Reply</a></span>"; //I WANT TO LOOP OUT THE COMMENTS HERE $thistweet .= "</div><!-- / --><span class='clear'></span></div><!--End Tweet -->"; return $thistweet; } }
**编辑* * *
我已经尝试了以下关于创建它的方法的答案,我现在已经成功地通过每条推文下面的相关评论来圈出“推文”。 但是我的问题是它正在为我的特定推文的每一条评论循环我的'推文',即
tweet 1 -comment 1.1 tweet 1 -comment 1.1 -comment 1.2 (Tweet 1 has 2 comments so loops out tweet 1 two times) tweet 2 -comment 2.1 tweet 2 -comment 2.1 -comment 2.2 tweet 2 -comment 2.1 -comment 2.2 -comment 2.3 (Tweet 2 has 3 comments so loops out tweet 2 three times)
我认为这是我的SQL查询的问题,因为我是使用JOIN语句的新手。 这是我目前用于查询的内容
"SELECT tweets.accountno, tweets.id,tweets.tweet,tweets.createdat,tweets.userid,users.name,users.avatar,users.biog,comments.comment FROM tweets INNER JOIN users ON tweets.userid = users.id JOIN comments ON tweets.id = comments.tweetid WHERE tweets.accountno ='123456' ORDER by tweets.ID DESC LIMIT 20"
有人能帮忙吗? 非常感激?
I know this has been asked a couple of times before but I've tried all the answers on this site and am still getting no where.
I am trying to create a twitter type feed that will loop out the posts and then loop out the associated comments for each post in the feed (similar to Facebook). I'm not sure if the best way to do this would be two separate queries or all in one query and also how do I loop it all out?
My database structure is as follows:
--TWEETS-- --COMMENTS-- --USERS-- id id id accountno accountno accountno userid userid email createdat createdat name tweet tweetid image comment
My PHP function is as follows:
function gettweets(){ $result = mysql_query("SELECT tweets.id,tweets.tweet,tweets.createdat,tweets.userid,users.name,users.avatar,users.biog FROM tweets INNER JOIN users ON tweets.userid = users.id WHERE tweets.accountno ='123456' ORDER by tweets.ID DESC LIMIT 20"); while($row = mysql_fetch_array( $result )) { $name = $row['name']; $biog = $row['biog']; $avatar = $row['avatar']; $newtweet= $row['tweet']; $tweetid = $row['id']; $timeago = ago($row['createdat']); $thistweet = ''; $thistweet .= "<div class='tweet' data-tweetid='$tweetid'>"; $thistweet .= "<div class='left'>"; $thistweet .= "<img width='45' height='45' src='$avatar' alt='placeholder+image'>"; $thistweet .= "</div><!-- / -->"; $thistweet .= "<div class='right'>"; $thistweet .= "<span class='name'>$name says</span>"; $thistweet .= "<p>"; $thistweet .= "$newtweet"; $thistweet .= "</p>"; $thistweet .= "<span class='replybar'> $timeago <a class='like' data-tweetid='$tweetid' href='' title=''>Like</a> | "; $thistweet .= "<a class='favourite' data-tweetid='$tweetid' href='' title=''>Favourite</a> | "; $thistweet .= "<a class='mainreply' href='' title=''>Reply</a></span>"; //I WANT TO LOOP OUT THE COMMENTS HERE $thistweet .= "</div><!-- / --><span class='clear'></span></div><!--End Tweet -->"; return $thistweet; } }
**EDIT***
I've tried the below answer regarding the way to create it and I am now succesfully managing to loop out the 'tweets' with the associated comments below each tweet. However my problem is that it is looping out my 'tweets' for every number of comments that I have for that particular tweet ie
tweet 1 -comment 1.1 tweet 1 -comment 1.1 -comment 1.2 (Tweet 1 has 2 comments so loops out tweet 1 two times) tweet 2 -comment 2.1 tweet 2 -comment 2.1 -comment 2.2 tweet 2 -comment 2.1 -comment 2.2 -comment 2.3 (Tweet 2 has 3 comments so loops out tweet 2 three times)
I think this is a problem with my SQL query as Im new to using JOIN statements. This is what I currently have for my query
"SELECT tweets.accountno, tweets.id,tweets.tweet,tweets.createdat,tweets.userid,users.name,users.avatar,users.biog,comments.comment FROM tweets INNER JOIN users ON tweets.userid = users.id JOIN comments ON tweets.id = comments.tweetid WHERE tweets.accountno ='123456' ORDER by tweets.ID DESC LIMIT 20"
Is anyone able to help? Much appreciated?
原文:https://stackoverflow.com/questions/10310855
最满意答案
for %%F in (*.pcap) do IF %%~zF GTR 1048576 if not exist "%%~dpnF.csv" tshark -r "%%F" -T fields -E header=y -E separator=, -E quote=d -e frame.number -e frame.time -e ip.src -e ip.dst -e data.text -e tcp.analysis.duplicate_ack -e tcp.analysis.out_of_order -e tcp.analysis.retransmission -e tcp.analysis.fast_retransmission -e tcp.analysis.spurious_retransmission -e tcp.analysis.zero_window -e tcp.stream -e tcp.srcport -e tcp.dstport -e data.len > "%%~dpnF.csv"**
仅当
%%F
中的文件大小大于1Mb时才应执行该行的其余部分for %%F in (*.pcap) do IF %%~zF GTR 1048576 if not exist "%%~dpnF.csv" tshark -r "%%F" -T fields -E header=y -E separator=, -E quote=d -e frame.number -e frame.time -e ip.src -e ip.dst -e data.text -e tcp.analysis.duplicate_ack -e tcp.analysis.out_of_order -e tcp.analysis.retransmission -e tcp.analysis.fast_retransmission -e tcp.analysis.spurious_retransmission -e tcp.analysis.zero_window -e tcp.stream -e tcp.srcport -e tcp.dstport -e data.len > "%%~dpnF.csv"**
should execute the rest of the line only if the size of the file in
%%F
is greater than 1Mb
相关问答
更多-
如何为if条件添加循环?(How to add loop for if condition?)[2022-08-11]
下面的shell脚本可能会按您的需要工作 #!/bin/sh if [ condition 1 ] statement; exit; fi i=1 while [ $i -lt 5 ] do if [ condition 2 ] statement; exit; else sleep 30 true $(( i++ )) fi done shell script below maybe works as you desire #!/bi ... -
您并不需要运行for循环来执行此操作。 你可以简单地通过运行一个简单的查询来检查它,这个查询将在排除数组后指定的所有记录之后进行检查: $ignore_ids = [9055954, 2736738, 1234, 2844725]; $this->db->where_not_in('add_family', $ignore_ids); You don't really need to run a for loop to do this. You can simply check it by runnin ...
-
该程序是错误的,因为它溢出了一个signed int,这在C中是未定义的行为。在某些环境中, 它将导致无限循环,但许多编译器实现符号溢出的方式与实现无符号溢出相同。 如果签名溢出像无符号溢出一样实现,那么在某些时候, i将变得太大而不能适应短小的内容,并且会环绕并变为0 - 这将打破循环。 基本上USHRT_MAX + 1产生0。 所以把i改为unsigned short i = 0就可以了。 The program is wrong as it overflows a signed int, which ...
-
任何条件需要表达式和操作符。 Do until exp1 op exp2 OR exp3 可能只有在exp3是一个布尔类型时才有效。 “”(String)不是。 所以它应该是这样的 Do Until Sheets("Sheet1").Cells(x, y).Value = stringOne Or Sheets("Sheet1").Cells(x, y).Value = "" Any condition needs expressions and operators. Do until exp1 ...
-
for %%F in (*.pcap) do IF %%~zF GTR 1048576 if not exist "%%~dpnF.csv" tshark -r "%%F" -T fields -E header=y -E separator=, -E quote=d -e frame.number -e frame.time -e ip.src -e ip.dst -e data.text -e tcp.analysis.duplicate_ack -e tcp.analysis.out_of_orde ...
-
由于exit_border_point可以是向量,请尝试使用any或all函数,如下所示: if (~any(exit_border_point)) 正如您可能猜到的,如果数组中的任何内容求值为true ,则返回true如果数组中的所有内容都为true ,则返回true 。 它们有点像||向量等价物 和&& 。 Since exit_border_point can be a vector, try using the any or all functions, like this: if (~any(e ...
-
对于人类和太空消耗而言,长篇if语句将难以阅读。 它会比for循环稍微快一些,但这不应该打扰你。 更好的方法是将for循环放在一个单独的函数中,该函数返回布尔值或将比较值存储在数组中并检查如下内容: var array = [1,2,3,4,5] if(array.contains(x)) { // x is one of the values } else { // x is not in the values } The long if statement is going to be ...
-
循环while条件为TRUE(Loop While condition is TRUE)[2023-07-15]
这是一个可能的解决方案。 它不使用while而是更通用的repeat 。 我编辑它使用一段while并保存几行。 set.seed(0) n <- 4 v <- numeric(n) i <- 0 while (i < n) { ith <- runif(1) if (sum(c(v, ith)) < 1) { i <- i+1 v[i] <- ith } } v # [1] 0.89669720 0.06178627 0.01339033 0.02333120 使用repea ... -
你的while循环在你询问他们是否想要再次播放之前结束。 将循环更改为: while(response == ('y')) { out.print("Rock-Paper-Scissors - pick your weapon [R,P,S] :: "); player = keyboard.next(); game.setPlayers(player); //game.determineWinner(); out.pr ...
-
echo一次并记录下这样的事实: $echoed = false; while($row>$played){ // not sure what this is doing $row is an array if($row['event_date'] == $date && !$echoed){ echo $echoed = '
TODAY,'.$date.' '; } } echo once and record the fact: $echoed = ...