我真的需要你的帮助。请帮我解决这个问题。
我有这两张表,relation
它们之间是user_id
. 我完成了选择我关注的人并将他们的图像显示在我的墙上。但是,我有一个奇怪的问题:照片按DESC
我想要的方式排序,但它们是按user_id
. 这意味着无论我先关注谁,他们的图像都会首先按DESC
.
我尝试了几乎所有可能的方法,以根据最新照片作为顶部对照片进行排序DESC
,但我做不到。这是我的表格,我将向您展示我尝试过的所有可能的事情:
CREATE TABLE IF NOT EXISTS `photos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`img` varchar(255) NOT NULL,
`about` text NOT NULL,
`date` varchar(222) NOT NULL,
`user_id` varchar(255) NOT NULL,
`likes` int(255) NOT NULL,
`down` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ;
CREATE TABLE IF NOT EXISTS `follow` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`followers` varchar(255) NOT NULL,
`following` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
}
一
Followers_photo.php,我following id
从中检索:
$the_user = mysql_query("SELECT * FROM users WHERE username = '$getuser'");
$tuser=mysql_fetch_array($the_user);
$tu_id = $tuser['id'];
$followers = mysql_query("SELECT distinct follow.*
FROM follow JOIN photos ON (follow.followers = $tu_id)
order by photos.date DESC");
$f_s_count = mysql_num_rows($followers);
- index.php 我在这里显示图像。
while($uim = mysql_fetch_assoc($followers)){ $i_id = $uim['following']; $followers_image = mysql_query("SELECT distinct photos.* FROM photos JOIN follow ON (photos.user_id = $i_id) GROUP BY RAND() order by date DESC");
以上是有效的,但正如我所提到的,它根据日期DESC
和user_id
我不想要的图像对图像进行排序。我希望它停止根据user_id
二
追随者照片.php
$the_user = mysql_query("SELECT * FROM users WHERE username = '$getuser'");
$tuser=mysql_fetch_array($the_user);
$isuser = mysql_num_rows($the_user);
$tu_id = $tuser['id'];
$tu_name =$tuser ['username'];
////users whos following Me
$followers = mysql_query(" SELECT distinct follow.* FROM photos join follow on follow.followers = photos.user_id WHERE follow.followers = $tu_id order by photos.date DESC");
//
$f_s_count = mysql_num_rows($followers);
索引.php
while($uim = mysql_fetch_assoc($followers)){
$i_id = $uim['following'];
$followers_image = mysql_query("SELECT * FROM photos WHERE user_id = '$i_id' order by date DESC ");
以上与第一步相同。谁能指出我正确的方法?根据我关注的人对照片进行排序date DESC
,最后发布的人优先。谢谢各位,非常感谢你们的帮助。对不起我的英语不好。
更新
现在有了 vegatripy 提供的解决方案,图像是重复的,而不是按需要排序。左边是现在显示的内容。我想要的是排序为正确的图像。有任何想法吗? http://i.stack.imgur.com/Cod6z.jpg
解决了
$followers = mysql_query("SELECT PHOTOs.IMG, follow.followers, follow.following, photos.date,photos.img,photos.likes,photos.down,photos.id,photos.about
FROM FOLLOW
JOIN PHOTOs ON ( PHOTOs.USER_ID = FOLLOW.FOLLOWING )
WHERE FOLLOW.FOLLOWERS =31
ORDER BY PHOTOs.DATE DESC");
$f_s_count = mysql_num_rows($followers);
while($fimage = mysql_fetch_assoc($followers)){
$i_id = $fimage['following'];
$disimg = $fimage['img'];
$disid = $fimage['id'];
$distime = $fimage['date'];
$i_like=$fimage['likes'];
$i_unlike=$fimage['down'];