Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

I would like to make a list

Posted on 2009-05-02
7
Medium Priority
?
240 Views
Last Modified: 2013-12-12
Hi there,

I have a list of members and by each member, it lists the "gifts" given by other members.
Sometimes a same "gift" is given numerous times.
I am trying to count each gift item and if they have
more than 5 of any type of gift, I would like to not list those
certain 5 and instead list a different graphic that indicates a group of
5 of them was given... the page lists 20 different members
at a time and grabs their list of gifts for a 20 members.

Can this be done?

This is what I have so far...

$sql_query3 = "SELECT user,thegift FROM giftsgivenlist WHERE user='$member7' ORDER BY id ASC LIMIT 20";
        $result3 = mysql_query($sql_query3);
        $gifts2="";
        while($row3 = mysql_fetch_array($result3))
        {
           $member  = $row3['user'];
           $gifts2  .= $row3['thegift'];
        }

$list .= "$member7, Gifts: $gifts2";


($gifts2 shows an image of what was given in a list)


Thanks!
0
Comment
Question by:yglobal
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24286812
Try something like this:
$sql_query3 = "SELECT user,thegift FROM giftsgivenlist WHERE user='$member7' ORDER BY id ASC LIMIT 20";
$result3 = mysql_query($sql_query3);
$gifts2 = array();
while($row3 = mysql_fetch_array($result3)) {
  $member  = $row3['user'];
  $thegift = $row3['thegift'];
  if(!in_array($thegift,array_keys($gifts2)))
    $gifts2[$thegift] = 1;
  else 
    $gifts2[$thegift] += 1;
}
$list .= "$member7, Gifts: ";
foreach($gifts2 as $thegift=>$count) {
  if($count>=5)
    $list .= '<img src="img/FiveGifts.jpg" alt="" />';
  else 
    $list .= $thegift;
}

Open in new window

0
 

Author Comment

by:yglobal
ID: 24287119
Hi!
It looks good so far, but... there are several different "gifts" and need to put a different image on each one that is given 5 times or more. Instead of the same image for each (the FiveGifts.jpg).
Like a diamond.gif would turn into a 5diamond.gif
A ruby.gif woud turn into a 5ruby.gif
ans so on...

can that be done?

thanks!
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24287204
Sure. Does 'thegift' column contain the complete <img> tag, or just the image name? Can you show an example of the 'thegift' column? Try this:
# if 'thegift' contains the image name only:
if($count>=5)
    $list .= '<img src="img/5'.$thegift.'" alt="" />';
  else 
    $list .= '<img src="img/'.$thegift.'" alt="" />';
 
# if 'thegift' contains the <img> tag:
if($count>=5)
    $list .= preg_replace('/([a-z]+\.gif)/i','5(\1)',$thegift);
  else 
    $list .= $thegift;

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.

 

Author Comment

by:yglobal
ID: 24287346
this is what is there now <img src=diamond.gif title="A Diamond">
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24287364
Try this, then:
if($count>=5)
  $list .= preg_replace('/([a-z]+\.gif)/i','5\1',$thegift);
else 
  $list .= $thegift;

Open in new window

0
 

Author Comment

by:yglobal
ID: 24287404
Hi !
I just tried it out but it is listing 1 first listed member's gifts with the 2nd... and the list keeps growing down the line (it is listing 25 members andall of the gifts on a page) can that be fixed to show only theirs for each member (but they are seen by everyone)

if needed this is the code solution for the same section of code:


$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";
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24287514
I'm not sure if I understand. Did the preg_replace() work? Does it group the duplicate gift images into one image?

To combine it with the code from your last message, try this:

<?php
$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 anicon FROM icons WHERE user='$member1' ORDER BY id ASC";
  $result3 = mysql_query($sql_query3);
  $icon="";
  while($row3 = mysql_fetch_array($result3)) {
    $icon  .= $row3['anicon']." ";
  }
  $list .="<div>$mypic1, $member1 said $message1<br>My icons: $icon<br><br>";
 
  $sql_query = "SELECT user,thegift FROM giftsgivenlist 
                 WHERE user='$member1' ORDER BY id ASC LIMIT 20";
  $result = mysql_query($sql_query);
  $gifts = array();
  while($row = mysql_fetch_array($result)) {
    $thegift = $row['thegift'];
    if(!in_array($thegift,array_keys($gifts)))
      $gifts[$thegift] = 1;
    else 
      $gifts[$thegift] += 1;
  }
  $list .= "Gifts: ";
  foreach($gifts as $thegift=>$count) {
    if($count>=5)
      $list .= preg_replace('/([a-z]+\.gif)/i','5\1',$thegift);
    else 
      $list .= $thegift;
    }
  }
  $list .= "</div>\n";
}
echo $list;
?>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question