我真的需要你的帮助。请帮我解决这个问题。
我有这两个表,它们之间的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);
while($ uim = mysql_fetch_assoc($ followers)){
$ i_id = $ uim ['follow']; $ followers_image = mysql_query(“SELECT distinct 照片。*来自照片JOIN跟随ON(photos.user_id = $ i_id) GROUP BY RAND()按日期排序DESC“);
以上是有效的,但正如我所提到的,它根据日期DESC
和我不想要的user_id
对图像进行排序。我希望它停止根据user_id
followers_photo.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);
index.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 ");
以上与第一步相同。谁能指出我正确的方法?根据{{1}}对我关注的人进行排序,其中帖子排在最后。谢谢你们,我非常感谢你们的帮助。抱歉我的英语不好。