php - Mysql select date from different table -
hye guys i'v problem selecting date table. have tables like
1) users table, 2)follow table, 3) photos table, etc.
i'm trying select date photos , not working. here mysql query. here i'm selecting followers follow table follower = user_id
followers_photo.php
$the_user = mysql_query("select * users 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 * follow followers ='$tu_id' order id desc"); $f_s_count = mysql_num_rows($followers);
and here i'm retrieving photos base on date , following id.
index.php
include('func/followers_photos.php'); if($f_s_count > '0') { while($uim = mysql_fetch_assoc($followers)){ $i_id = $uim['following']; $followers_image = mysql_query("select * photos user_id = '$i_id' order date"); $disimg = $fimage['img']; $disid = $fimage['id']; $distime = $fimage['date']; $i_like=$fimage['likes']; //$i_unlike=$fimage['down']; $likes_ip = mysql_query("select * voting_ip mes_id_fk = '$disid'"); $ipadd = mysql_fetch_assoc($likes_ip); $check_likes= $ipadd['mes_id_fk']; $user_follow_details = mysql_query("select * users id = '$i_id'"); $ufde = mysql_fetch_assoc($user_follow_details); $uiname = $ufde['username']; $uinim = $ufde['img']; $ip=$_server['remote_addr'];
ending brackets after html code.
above code works can't manage sort photos base on date because i'm selecting data table base on id.
here tried far.
$the_user = mysql_query("select * users 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 * follow,photos followers = photos.user_id order photos.date desc"); $f_s_count = mysql_num_rows($followers);
above code work select photos database , not the following id. mean user don't follow picture show.
what i'm trying accomplish select follow , sort photos photo date stored in photos table. i'm stuck , me out ? replies appreciated. sorry bad english.
edit
now works want shows images multiple times.
$followers = mysql_query("select * follow,photos photos.user_id = '$tu_id' , follow.followers = photos.user_id order photos.date desc");
another edit
now doesn't display images multiple times whenever post new image wont @ top still sort them base on id. little modification on @gongordon linoff suggestion
select distinct follow.* photos join follow on follow.followers = photos.user_id photos.user_id = $tu_id order photos.date desc;
did try this?
$followers = mysql_query("select * follow, photos follow.followers = photos.user_id , photos.user_id = '$i_id' order photos.date desc");
Comments
Post a Comment