【发布时间】:2013-01-11 01:46:16
【问题描述】:
我正在开发一个像 twitter 这样的社交工具,但我被困在“谁也在推特这个 twitter”上。
我的页面上有一个推特列表,我想显示谁也为每条推文发布了此推文。
我正在使用 MySQL + php + Smarty。
代码如下: /* ---- php ---- */
// Get twitters that tweeted over 200 times.
$sql = mysql_query("SELECT id, content, user, tweets FROM twitter_list WHERE tweets > '200'");
$twitter_array = array();
while($tweet_row = mysql_fetch_array($sql)){
array_push($twitter_array, $tweet_row);
// Get the users who tweeted these twitters.
$twitter_id = $tweet_row['id'];
// Find out 5 friends who also tweeted this twitter. twitter_relation stores who tweets what.
$friends_who_also_tweet = mysql_query("SELECT tid, twitter_id, user_id FROM tweet_relation WHERE twitter_id = '$twitter_id' ORDER BY tid DESC LIMIT 5");
$friends_who_also_tweet_array = array();
while($friends_who_also_tweet_row = mysql_fetch_array($friends_also_tweet_array)){
array_push($friends_who_also_tweet_array, $friends_who_also_tweet_row);
}
if($friends_who_also_tweet_array){
$sm->assign("fwat", $friends_who_also_tweet_array);
}
}
if($twitter_array){
$sm->assign("twitter", $twitter_array);
}
$smarty->display('twt.html');
/* ---- HTML: twt.html ---- */
...
{section name=twitter loop=$twitter}
<div class="content">{$twitter[twitter].content}</div>
<div class="who_also_tweet">
{section name=who loop=$fwat}
<div class="i_also_tweet">{$fwat[who].user_id}</div>
{/section}
</div>
{/section}
我希望得到 twitter 数组,并为每个 twitter 检索 5 个发推文的用户。但它只显示第一个 twitter 的用户,我怀疑 while() 可能是错误的但找不到它。任何人都可以帮我一把吗?非常感谢。
【问题讨论】:
-
花一点时间重新格式化该代码,您可能会得到更多帮助。
-
@ChrisMoll 你的意思是这个想法是正确的,对吧?
-
好吧,我并不完全理解目标。您是在创建自己的“推特”,还是使用真实的东西?真正的 Twitter 有这样的 API,但你从自己的数据库中提取所有内容。
-
@ChrisMoll 这是我自己构建的类似推特的东西。我认为隐喻会是一种更快的方式来理解我在做什么......