solve this please..

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

8 replies · 665 views · started 14 years ago · 1 min read

3 participants
icedroplet1987 Senior · 258 posts #1

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..

$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);
   }
something else Fellow · 2,296 posts #2

Try:

$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); 
   } 
icedroplet1987 Senior · 258 posts #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. 🙁

arnage Lead · 811 posts #4

🙂

$uid=$db->select("SELECT userid FROM users WHERE username='".$shout->username."' LIMIT 1");
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
icedroplet1987 Senior · 258 posts #5

arnage wrote: :)

$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..

something else Fellow · 2,296 posts #6

to reduce calls to database you can use:

$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

icedroplet1987 Senior · 258 posts #7

something else wrote: to reduce calls to database you can use:

$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??

arnage Lead · 811 posts #8

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

$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***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close