Re: Riderz 'how to create last activities list'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Re: Riderz 'how to create last activities list'

    For some strange reason the mobile version of this site doesnt allow me to send messages. If i got ur msg rite, it was about creating the most recent activities. I assume u already knw ur database enuf to make a table 4 it.
    PHP Code:
    $sql "SELECT * FROM user_activities ORDER BY act_time DESC LIMIT 5";
    $query mysql_query($sql);
    if(
    mysql_num_rows($query) > 0)
    {
    while(
    $results mysql_fetch_array($query)){
    $user getnick_uid($results['user_id']);
    echo 
    "{$user} {$results['action']} @ {$results['act_time']}<br/>";
    }
    }else{
    echo 
    'wtf! No activities? Boring site!';

    forgive me if i didnt get sum mysql functions ryt. I use PHP Doctrine for managing databases in all my projects now, im already used to creating models and yaml schemas sorry bt u get the idea though.

    #2
    yo rider, i'll explain it to you the easiest way possible... no real coding skill needed...

    copy paste edit... I did it using the forums and created new table to log action, what to and time, etc... easy as 1 2 3... like under ten minutes...
    C3 Themes: http://c3themes.wen.ru/index.html
    Find Files: http://mystarter.tk/?goto=X-search

    Comment


      #3
      well u can copy paste, bt i wudnt recommend that.

      Comment


        #4
        A brilliant idea would be, create a class that helps manage the activity functions
        PHP Code:
        <?php defined('__CK__') OR die('Silence is golden.');
        class 
        Activity_Log {
        public 
        $auto_clear TRUE;
        protected 
        $expiry_time 86000;

        public function 
        __construct(){
         if(
        $this->auto_clear){
         
        /// auto_clear old activities
         
        $this->clear_old($this->expiry_time);
         }
        }

        public function 
        clear_old($expiry_time 86000){
         
        /// check for old acts
         
        $time_limit time() - $expiry_time;
         
        $num_rows mysql_num_rows(mysql_query("SELECT * FROM user_activities WHERE act_time < {$time_limit}"));
         if(
        $num_rows 0){
          
        mysql_query("DELETE FROM user_activities WHERE act_time < {$time_limit}");
         }
        }

        public function 
        add_activity($activity,$uid NULL){
        $updated FALSE;
         
        /// Update MANY activities at once
         
        if(is_array($activity) AND count($activity) > 0){
         
        /// Update each record
          
        foreach($activity as $act){
          
        $updated mysql_query("INSERT INTO user_activities SET action = '".$act['msg']."', uid = '".(int) $act['uid']."', act_time = '".(int) $act['time']."'");
         }
         }else{
         
        /// Update single record
          
        $updated mysql_query("INSERT INTO user_activities SET action = '".$activity."', uid = '".(int) $uid."', act_time = '".time()."'");
         }
        return (
        $updated) ? TRUE FALSE;
        }

        public function 
        delete_activity($id){
        $deleted mysql_query("DELETE FROM user_activity WHERE id = '".(int) $id."'");
        return (
        $deleted) ? TRUE FALSE;
        }
        }
        ?>

        Comment


          #5
          You can add other methods to the class.
          Quick explanation:
          1. Instantiate the class
          PHP Code:
          include('../path/to/class_file.php');
          define('__CK__'TRUE);
          $activity = new Activity_Logger;
          /// NOTE: It automagically clears old activities 
          2. Adding activities for a user.
          2.1 Single activity.
          PHP Code:
          /// Assuming class has been instantiated
          $act 'just joined mGiGS.';
          $activity->add_activity($act,$uid); 
          2.2 Multiple activities at once.
          PHP Code:
          $acts = array(
           [
          0] => array('msg' => 'just joined mGiGS.''uid' => $uid'time' => time()),
           [
          1] => array('msg' => 'also updated his profile''uid' => $uid'time' => time())
          );

          $activity->add_activity($acts); 
          3. Deleting a record
          PHP Code:
          $delornot = ($activity->delete_activity($activity_id)) ? 'was deleted successfully.' 'record #'.$activity_id.' could not be deleted.';
          echo 
          'Activity '.$delornot
          Last edited by CreativityKills; 07.06.10, 06:25.

          Comment


            #6
            rider dude pm me.. i was busy last few days. or send me a mail ill fwrd the full code


            ....................................
            http://photomag.lk/
            ....................................

            Comment

            Working...
            X