solve this please..

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

    solve this please..

    how i add userid to show profile in this condition.. i am getting multiple results thats why not able to get uid from user table..

    PHP Code:
    $shoutlist=$db->select("SELECT message, username, groupid, mstime FROM shout ORDER BY mstime DESC LIMIT 0,15");
       

       
    if(
    $shoutlist)
       {
          print 
    "<br/>";
          
    $allshouts="";
       foreach(
    $shoutlist as $shout)
       {
    if(
    strlen($shout->message) > 160){   $shout->message substr($shout->message,0,160)."~";   }    $shout->message=bbcode(htmlentities($shout->message)); 
     
    $shout->message=smiley($shout->message);
    $TimeZone="+5.30";
    $mstime=$shout->mstime + ($TimeZone 60 60); 
    $mstime=date("g:ia",$mstime);

    $uid=mysql_fetch_array(mysql_query("SELECT userid FROM users WHERE username='".$shout->username."'")); // getting multiple usernames as limit defined to 15 .. how i do it?

    $allshouts .= "<span style=\"font:normal 8pt verdana;\"><a href=\"".$config->url."profile.php?uid=".$uid[0]."\"><font color=\"".$group[$shout->groupid]['color']."\"><b>".$shout->username."</b></font></a>($mstime)-->".$shout->message."</span><br/>";
       }
          print 
    $allshouts;
          print 
    "<br/>";
          unset(
    $shoutlist);unset($allshouts);
       } 

    #2
    Try:
    PHP Code:
    $shoutlist=$db->select("SELECT message, username, groupid, mstime FROM shout ORDER BY mstime DESC LIMIT 0,15"); 
        

        
    if(
    $shoutlist
       { 
          print 
    "<br/>"
          
    $allshouts=""
       foreach(
    $shoutlist as $shout
       { 
    if(
    strlen($shout->message) > 160){   $shout->message substr($shout->message,0,160)."~";   }    $shout->message=bbcode(htmlentities($shout->message));  
     
    $shout->message=smiley($shout->message); 
    $TimeZone="+5.30"
    $mstime=$shout->mstime + ($TimeZone 60 60);  
    $mstime=date("g:ia",$mstime);

    $uid=$db->select("SELECT userid FROM users WHERE username='".$shout->username."'");
    // to save 15 calls to database you could insert another row on your shout sql for user id ... which would help speed your site up :)
    $allshouts .= "<span style=\"font:normal 8pt verdana;\"><a href=\"".$config->url."profile.php?uid=".$uid->userid."\"><font color=\"".$group[$shout->groupid]['color']."\"><b>".$shout->username."</b></font></a>($mstime)-->".$shout->message."</span><br/>";

          print 
    $allshouts
          print 
    "<br/>"
          unset(
    $shoutlist);unset($allshouts); 
       } 

    Comment


      #3
      i tried this way too, it doesnt work. And i know its not good to call database again and again but even after adding one more row to my shout dql it doesnt help me as then also it will show up all 15 userids together. i just want to get one userid somehow. plese anyone figure it out.

      Comment


        #4

        PHP Code:
        $uid=$db->select("SELECT userid FROM users WHERE username='".$shout->username."' LIMIT 1"); 
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


          #5
          Originally posted by arnage View Post

          PHP Code:
          $uid=$db->select("SELECT userid FROM users WHERE username='".$shout->username."' LIMIT 1"); 
          hmm, will this change

          $shout->username to one?? i think, it will display one user as limit defined but i already declared $shout->user = 15 .. so it doesnt make sense ..
          hmmm..

          Comment


            #6
            to reduce calls to database you can use:
            PHP Code:
            $shoutlist $sql->query("SELECT S.message, S.username, S.groupid, S.mstime, U.userid FROM shout S LEFT JOIN users U ON S.username=U.username ORDER BY S.mstime DESC LIMIT 0,15");

            //text here to get rid of opera bug 
            that way you have got userid in your sql eg:
            $shout->userid

            Comment


              #7
              Originally posted by something else View Post
              to reduce calls to database you can use:
              PHP Code:
              $shoutlist $sql->query("SELECT S.message, S.username, S.groupid, S.mstime, U.userid FROM shout S LEFT JOIN users U ON S.username=U.username ORDER BY S.mstime DESC LIMIT 0,15");

              //text here to get rid of opera bug 
              that way you have got userid in your sql eg:
              $shout->userid
              Will it not affect other codes??

              Comment


                #8
                I didn't understand in the first place, try this.

                PHP Code:
                $shoutlist mysql_query("SELECT message, username, groupid, mstime FROM shout ORDER BY mstime DESC LIMIT 0,15");
                if (
                mysql_num_rows($shoutlist)) {
                print 
                "<br/>"
                $allshouts=""
                while (
                $shout mysql_fetch_object($shoutlist)) {
                $query mysql_query("SELECT userid FROM users WHERE username='".$shout->username."'"));
                while (
                $uid mysql_fetch_array($query) {
                if (
                strlen($shout->message) > 160) {
                $shout->message substr($shout->message,0,160)."~";
                }
                $shout->message=bbcode(htmlentities($shout->message));  
                $shout->message=smiley($shout->message); 
                $TimeZone="+5.30"
                $mstime=$shout->mstime + ($TimeZone 60 60);  
                $mstime=date("g:ia",$mstime); 
                echo 
                "<span style=\"font:normal 8pt verdana;\"><a href=\"".$config->url."profile.php?uid=".$uid[0]."\"><font color=\"".$group[$shout->groupid]['color']."\"><b>".$shout->username."</b></font></a>($mstime)-->".$shout->message."</span><br/>"
                }
                }
                print 
                "<br/>"

                <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                Comment


                  #9
                  Originally posted by icedroplet1987 View Post
                  Will it not affect other codes??
                  nope
                  ....

                  Comment

                  Working...
                  X