PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    body text not coming up?

    Share
    avatar
    mattastic

    Number of posts : 25
    Registration date : 2009-10-11

    body text not coming up?

    Post  mattastic on Mon Nov 21, 2011 3:31 pm

    i have this facebook looking news feed right here but the thing is the body text wont show up when its submitted, yet when i look in the database its there!

    Code:

    function displayPosts($username,$limit=0){
      global $database, $session;
     
      $user_string = "'".implode("','",$username)."'";
      $extra =  " AND user_id IN ($user_string)";

        if ($limit > 0){
          $extra = "LIMIT $limit";
      } else {
          $extra = ''; 
      }
         
      $q = "SELECT user_id,body,stamp "
          ."FROM ".TBL_POSTS." WHERE user_id IN ($user_string) ORDER BY stamp DESC $extra";
          echo $q;
      // This query is for own posts only 
      //$q = "SELECT body,stamp "
      //    ."FROM ".TBL_POSTS." WHERE user_id = '$username' ORDER BY stamp DESC";
      $result = $database->query($q);
      //error checkx $result = mysql_query ($q) or die(mysql_error());

     
      /* Error occurred, return given name by default */
      $num_rows = mysql_numrows($result);
      if(!$result || ($num_rows < 0)){
          echo "Error displaying info";
          return;
      }
      if($num_rows == 0){
          echo "There are no status updates.";
          return;
      }
     
      /* Display table contents */
      echo "[table align='"left"' border='"0"' cellspacing='"0"' cellpadding='"5"']";
      for($i=0; $i<$num_rows; $i  ){
            $datetime = mysql_result($result,$i,"stamp");
          echo "[tr valign="top"]\n";
          echo "[td]".mysql_result($result,$i,"user_id")."[/td]\n";
          echo "[td]".mysql_result($result,$i,"body")."
    \n";
          echo $datetime."[/td]\n";
          echo "[/tr]\n";
      }
      echo "[/table]
    ";
    }
    avatar
    Linchpin311

    Number of posts : 220
    Age : 32
    Localisation : Long Island
    Registration date : 2007-05-14

    Re: body text not coming up?

    Post  Linchpin311 on Mon Nov 21, 2011 8:08 pm

    are the timestamp and the userid also not being displayed or is it just the body that is affected?


    _________________
    in the end, the universe tends to unfold as it should...

    Also note that it is your responsibility to die() if necessary.
    avatar
    nean

    Number of posts : 2
    Registration date : 2011-10-23

    Re: body text not coming up?

    Post  nean on Fri Dec 02, 2011 6:19 pm

    Code:


    /*
    @param user_array is usually the array of users or it may be a just a single username(i.e string).
    @param startfrom gets the starting post of query.
    @param limit get the number of posts from $startfrom.
    */
    function displayPosts($user_array, $startfrom = 0, $limit = 0)
    {
       global $database, $session;

       if(is_array($username))
       {
          foreach ($user_array as $value)
          {
             $value = mysql_real_escape_string($value);
          }
          $user_string = "'".implode('","',$user_array)."'";
          $extra_user = "IN ({$user_string})";
       }
       else if(empty($username))
       {
          $user_string = "= ".mysql_real_escape_string($session->username);
       }
       else if(is_string($username))
       {
          $user_string = "= ".mysql_real_escape_string($username);
       }
       else
       {
          echo "Error Processing Input";
       }


       if ($limit > 0)
       {
          $extra_limit = "LIMIT {$startfrom},{$limit}";
       }
       else
       {
          $extra_limit = ''; 
       }
         
       $q = "SELECT user_id,body,stamp "
       ."FROM ".TBL_POSTS." WHERE user_id {$extra_user} ORDER BY stamp DESC {$extra_limit}";
       echo $q;
       /* This query is for own posts only 
          $q = "SELECT body,stamp "
             ."FROM ".TBL_POSTS." WHERE user_id = {$extra_user} ORDER BY stamp DESC {$extra_limit}";
       */
       
       $result = $database->query($q);

       //error checkx $result = mysql_query ($q) or die(mysql_error());
       // Error occurred, return given name by default

       $num_rows = mysql_numrows($result);
       if(!$result || ($num_rows < 0))
       {
          echo "Error displaying info";
          return;
       }
       if($num_rows == 0)
       {
          echo "There are no status updates.";
          return;
       }
     
       /* Display table contents */
       echo "[table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"]";
       for($i=0; $i<$num_rows; $i++)
       {
          $datetime = mysql_result($result,$i,"stamp");
          echo "[tr valign=\"top\"]\n";
             echo "[td]".mysql_result($result,$i,"user_id")."[/td]\n";
             echo "[td]".mysql_result($result,$i,"body")."\n".$datetime."[/td]\n";
             echo "[/tr]\n";
         }
         echo "[/table]";
    }

    Try using this function. I havent tested it, But it should work. I have just sanitized the username array, introduced a new parameter and made a few changes. Hope this works.
    Smile

    Example usage:

    Code:

    //To display latest ten posts of abc, def, efg.
    $userarray = array('abc','def','efg');
    displayPosts($userarray,0,10);

    //To display 10-20 posts of abc.
    displayPosts("abc",10,10);

    Sponsored content

    Re: body text not coming up?

    Post  Sponsored content


      Current date/time is Sun Oct 22, 2017 4:53 pm