limit amount of records from database via php?-VBForums
Results 1 to 5 of 5

Thread: limit amount of records from database via php?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    871

    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> ';
    }
    
    }
    
    
    ?>

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,502

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    871

    Re: limit amount of records from database via php?

    Hi,

    Which line do i replace with that?

    Thanks,
    Jamie,

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    871

    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>";
    }
    
    
    
    
    ?>

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    871

    Re: limit amount of records from database via php?

    Any ideas?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.