• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Trying to list icons for users...

I am trying to list 25 members along with each members latest chat message and photo.
Each member also has several icons listed in another table for their username.
I can get the message list and the user okay, but when it trys to grab all of their icons,
it only grabs the first icon listed for each user when they have an icon listed multple times.
Like some users have a dozen to be listed and others just have a few or none.

This is what I have so far...

$connection = mysql_connect ("localhost","myuser", "mypass") or die ("Cannot make the connection");
$db = mysql_select_db ("data",$connection) or die ("Cannot connect to database");
$sql_query1 = "SELECT user,message FROM chat ORDER BY numbss DESC LIMIT 25";
$result1 = mysql_query($sql_query1);

while ($row1 = mysql_fetch_assoc($result1))
{
  $member1  = $row1['user'];
  $message1 = $row1['message'];


        $sql_query2 = "SELECT picimage FROM members WHERE user='$member1' ORDER BY id DESC LIMIT 1";
        $result2 = mysql_query($sql_query2);
        $row2 = mysql_fetch_array($result2);
        $mypic1  = $row2['picimage'];

$sql_query3 = "SELECT user,anicon FROM icons WHERE user='$member1' ORDER BY id ASC";
        $result3 = mysql_query($sql_query3);
        $row3 = mysql_fetch_array($result3);
        $member  = $row3['user'];
        $icon  = $row3['anicon'];

$list .="$mypic1, $member1 said $message1<br>My icons: $icon<br><br>";

echo "$list";

You see, it will only list one icon in the last part. How do I make it grab all the icons and list them all for each user?

thanks!

0
yglobal
Asked:
yglobal
  • 3
  • 3
1 Solution
 
joep1978Commented:
You need to loop through the icons and add them to the string to be displayed to the user.  Try this
$connection = mysql_connect ("localhost","myuser", "mypass") or die ("Cannot make the connection");
$db = mysql_select_db ("data",$connection) or die ("Cannot connect to database");
$sql_query1 = "SELECT user,message FROM chat ORDER BY numbss DESC LIMIT 25";
$result1 = mysql_query($sql_query1);
 
while ($row1 = mysql_fetch_assoc($result1))
{
  $member1  = $row1['user'];
  $message1 = $row1['message'];
 
 
        $sql_query2 = "SELECT picimage FROM members WHERE user='$member1' ORDER BY id DESC LIMIT 1";
        $result2 = mysql_query($sql_query2);
        $row2 = mysql_fetch_array($result2);
        $mypic1  = $row2['picimage'];
 
$sql_query3 = "SELECT user,anicon FROM icons WHERE user='$member1' ORDER BY id ASC";
        $result3 = mysql_query($sql_query3);
        while($row3 = mysql_fetch_array($result3))
        {
           $member  = $row3['user'];
           $icon  .= $row3['anicon']." ";
        }
$list .="$mypic1, $member1 said $message1<br>My icons: $icon<br><br>";
 
echo "$list";

Open in new window

0
 
yglobalAuthor Commented:
thank you but it is still only grabbing their first icon?
0
 
joep1978Commented:
If there are multiple rows for a user in the icons table then it should be displaying each icon separated by a space.  Actually I just made a slight fix, but I don't know why you're only seeing one icon per user if there's more than one row per user in the icons table
$connection = mysql_connect ("localhost","myuser", "mypass") or die ("Cannot make the connection");
$db = mysql_select_db ("data",$connection) or die ("Cannot connect to database");
$sql_query1 = "SELECT user,message FROM chat ORDER BY numbss DESC LIMIT 25";
$result1 = mysql_query($sql_query1);
 
while ($row1 = mysql_fetch_assoc($result1))
{
  $member1  = $row1['user'];
  $message1 = $row1['message'];
 
 
        $sql_query2 = "SELECT picimage FROM members WHERE user='$member1' ORDER BY id DESC LIMIT 1";
        $result2 = mysql_query($sql_query2);
        $row2 = mysql_fetch_array($result2);
        $mypic1  = $row2['picimage'];
 
$sql_query3 = "SELECT user,anicon FROM icons WHERE user='$member1' ORDER BY id ASC";
        $result3 = mysql_query($sql_query3);
        $icon="";
        while($row3 = mysql_fetch_array($result3))
        {
           $member  = $row3['user'];
           $icon  .= $row3['anicon']." ";
        }
$list .="$mypic1, $member1 said $message1<br>My icons: $icon<br><br>";
 
echo "$list";

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
yglobalAuthor Commented:
Okay it is listing them all for a 1 user (good)... but the first users icons copies down to the 2nd, and then the third and so on and keeps adding onto them.
So if the first user has 2, it shows the next person as having 4 and then grows bigger down the line, all with #1 icons
0
 
joep1978Commented:
Sorry that was the bug i fixed in the last update I posted :)
0
 
yglobalAuthor Commented:
great!! thank you so much. I love this site
-maryanne
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now