-
Feb 8th, 2012, 08:20 PM
#1
Thread Starter
Fanatic Member
limit amount of records from database via php?
Hi guy's below is my code which displays the most recent activity of users that i am subscribed to on my website... the code orders the latest activity via time. I am trying to limit to display just 10 records in total, however, the code below for some reason limits it to 10 records per person im subscribed, i.e if i am subscribed to 5 people it will display 50 record..
How can i make it display only 10 most recent items from all users, not per user?
Thanks
Jamie
Code:
<?
$query = mysql_query ( "SELECT * FROM `Subscriptions` WHERE `subscriber` = '$id'");
while ( $sched = mysql_fetch_object ( $query ) )
{
$query1 = mysql_query ( "SELECT * FROM `Activity` WHERE `Username` = '$sched->subscribed' order by time desc Limit 0,10" );
while ( $sched1 = mysql_fetch_object ( $query1 ) )
{
$subscribed1 = mysql_query ( "SELECT * FROM `users` WHERE `Username` = '$sched->subscribed'" );
$sub = mysql_fetch_object ( $subscribed1);
echo '<div class ="smallertxt"><img src ="'.$sched1->Image.'.png" height ="11" width ="11"> <b><a href ="#id='.$sub->username.'">'.$sub->name.'</a></b> <font color ="white"> '.$sched1->Activity.' </font> </b></b> ';
}
}
?>
-
Feb 8th, 2012, 08:29 PM
#2
Re: limit amount of records from database via php?
Code:
SELECT * FROM Activity WHERE Username IN (SELECT Username FROM Subscriptions WHERE subscriber = $id) ORDER BY time DESC LIMIT 10
-
Feb 8th, 2012, 08:44 PM
#3
Thread Starter
Fanatic Member
Re: limit amount of records from database via php?
Hi,
Which line do i replace with that?
Thanks,
Jamie,
-
Feb 8th, 2012, 09:09 PM
#4
Thread Starter
Fanatic Member
Re: limit amount of records from database via php?
Hi there, I have tried the following, and its printing 10 records,how ever its not printing sub->name e.t.c
it prints the activity but not sub->name e.t.c
thanks,
Jamie.
Code:
<?
$query1 = mysql_query ( "SELECT * FROM `Activity` WHERE `username` IN (SELECT `username` FROM `Subscriptions` WHERE `subscriber` = '$id') ORDER BY time DESC LIMIT 10");
while ( $sched1 = mysql_fetch_object ( $query1 ) )
{
$subscribed1 = mysql_query ( "SELECT * FROM `users` WHERE `Username` = '$sched1->subscribed'" );
$sub = mysql_fetch_object ( $subscribed1);
$session_time ="$sched1->Time";
//$session_time=time();
echo '<div class ="smallertxt"><img src ="'.$sched1->Image.'.png" height ="11" width ="11"> <b><a href ="#'.$sub->username.'">'.$sub->name.'</a></b> <font color ="white"> '.$sched1->Activity.' </font> </b></b> ';
echo"<font size ='1' color ='#d91a01'>";
$thetime = time_stamp($session_time); echo"</font><br><br>
</div>";
}
?>
-
Feb 9th, 2012, 07:37 AM
#5
Thread Starter
Fanatic Member
Re: limit amount of records from database via php?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|