PHP Login System with Admin Features

Would you like to react to this message? Create an account in a few clicks or log in to continue.
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


3 posters

    body text not coming up?

    mattastic
    mattastic


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

    body text not coming up? Empty body text not coming up?

    Post  mattastic 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]
    ";
    }
    Linchpin311
    Linchpin311


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

    body text not coming up? Empty Re: body text not coming up?

    Post  Linchpin311 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?
    nean
    nean


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

    body text not coming up? Empty Re: body text not coming up?

    Post  nean 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


    body text not coming up? Empty Re: body text not coming up?

    Post  Sponsored content

      Similar topics

      -

      Current date/time is Fri May 17, 2024 6:29 am