我的网站使用一张用于墙贴的表格(“users_wall”)和一张用于关注者的表格(“users_follow”)。wallposts 表看起来像这样(或多或少):
ID NAME USER_ID (the id of the wall it's posted on) CONTENT
1 James 3 Hi!
2 Jim 3 Hey there!
关注者/下表如下所示:
ID HEFOLLOWS THISGUY
1 James Jim
2 Jim James
我怎样才能用这个来制作工作台供稿?我目前有一个提要,但我发现无法按帖子的 id 排序,而不是发帖的人。我的看起来像:
James: Hey (15th)
James: Hi! (13th)
Jim: Hi! (14th)
当我想要它时:
James: Hey (15th)
Jim: Hi! (14th)
James: Hi! (13th)
那么我该怎么做呢?请解释一下,而不是把我送到一般的 mysql/php 学习网站。
谢谢 :)
编辑:这是我制作新闻提要的基本版本:
<?php
$getfollowing = mysql_query("SELECT * FROM users_follow WHERE hefollows = '$username'");
while ($row = mysql_fetch_assoc($getfollowing)){
$followername = $row['thisguy'];
$getposts = mysql_query("SELECT * FROM users_wall WHERE name = '$followername' SORT BY id DESC");
while ($rows = mysql_fetch_assoc($getposts){
$date = $rows['date']
(...)
?>
<div class="share">
<?php echo($nameofposter); ?>
<br />
<?php echo($share_content); ?> ( <?php echo($date); ?> )
</div>
<?php
}
?>
这将导致:
<div class="share">
James
<br />
Hey (15th)
</div>
<div class="share">
James
<br />
Hi! (13th)
</div>
<div class="share">
Jim
<br />
Hi! (14th)
</div>
因为James在数据库中是第一位的,并且是按照follower/following而不是share的ID排序的。