Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Array Help

  1. #1
    New Coder
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array Help

    Hi

    Just need an help on arrays.

    MySQL Table structure.

    ID name value
    1 c01 abc
    2 c01 def
    3 c02 xyz

    Here i want to structure the data in such a way that name column should be index of array and values should be mapped to index for eg.
    Array(
    [1] => Array ( [c01] => array([0] => abc [1] => def
    [2] => Array ( [c02] => array([0] => xyz
    )

    Thanks in advance.
    -------------------------
    Shailesh Patil
    -------------------------

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Use this code.. obviously you will have to connect to the database first and fix the query to have the right table name, but this will do what you want.

    PHP Code:
    $result mysql_query("SELECT * FROM `table`");
    while (
    $row mysql_fetch_assoc($result)) {
        
    $array[$row['name']][] = $row['value'];


  • #3
    New Coder
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey thanks buddy.
    It worked out.
    -------------------------
    Shailesh Patil
    -------------------------


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •