Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 33
  1. #1
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    Is there a function that gets the same values in an array and just puts them as one? Then say how many times that value has occured?

    for example i got my data from a column in a mysql database then i want to list the array on the page, but i want only 1 showing of identical values. Then have a number saying how many times each value has occurred?

    thanks
    JR

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    http://www.php.net/array_unique ? I don't get what you're saying.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    thanks thats what i am looking for i think...

    what i exactly want is this...

    using the example on there if i had a column in a mysql database called colours containing...

    Green
    Red
    Green
    Red
    Blue
    Green

    i want to use php to get it displayed on the page like this...

    3 Green
    2 Red
    1 Blue
    JR

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Classic computing problem. Thankfully associated arrays in PHP make it a lot easier:
    PHP Code:
    $a = array();
    foreach (
    $originallist as $key => $value)
    {
        if (!isset(
    $a[$key])) $a[$key] = 1;
        else 
    $a[$key]++;
    }
    foreach (
    $a as $key => $value)
    {
        echo 
    "$value occurances of $key<br>";

    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    is this just an example or will it work?
    JR

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    I might have gotten $key and $value messed up in the first block but theoretically it should work.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    no it doesn't work i don't think (well i am a complete php newbie, i didn't know how to query properly until a few hours ago )

    i have however found a way using SQL
    Code:
    SELECT DISTINCT col_name FROM table_name
    the only problem with this is i can't count how many times each one occurs :tired:
    JR

  9. #8
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    i have lost my patience with this now, so i will explain everything in hope that it can be done


    PHP Code:
    $refq "SELECT * FROM forum_users WHERE user_id > 0";
    $result2 mysql_query($refq)
                or die(
    "Could Not Execute Query");

    while(
    $row2 mysql_fetch_array($result2)) {
    $ranking .= "<tr>
    <td bgcolor=#e6e6e6 width=350 style='font-size: 10px'>"
    .$row2['user_refer']."
    </td>
    <td bgcolor=#dddddd width=350 style='font-size: 10px'>[b]0[/b]</td>
    </tr>"
    ;

    I have <?php echo $ranking; ?> in the body section of my page.

    On this part .$row2['user_refer']." i want to display the referral, but i want identical values only displayed once and then the bold 0 saying how many occurences of the value there is. For Example...

    If the user_refer column was like this...
    Google
    Google
    UsernameA
    UsernameB
    Google
    UsernameA

    i would want it to display on the page like this...
    Google&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;3
    UsernameA&nbsp;&nbsp;&nbsp;&nbsp;2
    UsernameB&nbsp;&nbsp;&nbsp;&nbsp;1

    thanks
    JR

  10. #9
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Code:
    SELECT user_refer, COUNT(user_refer) FROM forum_users
    Never SELECT *.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  11. #10
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    didn't work

    why never select *?
    JR


Page 1 of 4 1 2 3 ... LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:18 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com