MySQL Forums
Forum List  »  PHP

Help: select date from another table
Posted by: koshWTF kosh
Date: August 07, 2013 02:23AM

hye guys i'v a problem with selecting a date from another table.
basically i have users table, follow table, photos table, etc.
i'm trying to select the date from photos but its not working.
here is my follow table
here i'm selecting the followers from the follow table where the follower = the user_id

----------------------------------------------------------------------------------

$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'];
////users whos following Me
$followers = mysql_query("SELECT * FROM follow WHERE followers ='$tu_id' order by id desc");
$f_s_count = mysql_num_rows($followers);


----------------------------------------------------------------------------------
and here i'm retrieving the photos base on their date and the following id.
----------------------------------------------------------------------------------

if($f_s_count > '0'){
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");

..........
----------------------------------------------------------------------------------

above code works but i can't manage to sort the photos base on their date because i'm selecting data from the table base on the id.

here is what i tried so far.

----------------------------------------------------------------------------------

$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'];
////users whos following Me
$followers = mysql_query("SELECT * FROM follow,photos WHERE followers = photos.user_id order by photos.date desc");
$f_s_count = mysql_num_rows($followers);

----------------------------------------------------------------------------------
above code will work but will select all the photos from the database and not from the the following id. what i mean is even the user i don't follow their picture will show.

what i'm trying to accomplish is select from who i follow and sort their photos by the photo date which is stored in photos table. i'm really stuck , anyone could help me out ? your replies are appreciated. sorry for my bad english.



Edited 1 time(s). Last edit at 08/07/2013 02:24AM by koshWTF kosh.

Options: ReplyQuote


Subject
Written By
Posted
Help: select date from another table
August 07, 2013 02:23AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.