1. Post #1
    cas97's Avatar
    August 2009
    987 Posts
    So I have a table like:
    [id | firstName | lastName | type | etc ]

    and it holds a list of people's first, last names, and information about what they made. My problem is that I'd have like
    [ 1 | person_A | something | painting | etc]
    [ 2 | person_A | something | something | etc]
    [ 3 | person_A | something | else | etc]

    because they've made more than one thing. I'd like to just get one row with person_A, but has everything in the type column.

    Would it be a good idea to get everything (SELECT * FROM stuff) and then with a loop in php, add them to an array if they're not already in it, and if they are, just add onto it. Eventually turning into
    //Something like
    $peoples = array("id of row" => array("first name","last name","etc","type" => array("painting","something","else")),/*so on*/);

    or some trick with mysql?

    Solved: use DISTINCT!

  2. Post #2
    Gold Member
    h2ooooooo's Avatar
    June 2007
    979 Posts
    You should just be able to do a

    SELECT type FROM stuff WHERE firstName = 'person_A'

    And then loop through it and add it to an array.


    And of course that's not just one row, but does it matter, when you do it on the PHP side?

  3. Post #3
    cas97's Avatar
    August 2009
    987 Posts
    Well I want to have it output like a
    'there are [x] people....'
    or in other places
    '[first] [last] has made [types]'
    your sql will just get me for one person

    or 'there are [x] projects by [y] people'

  4. Post #4
    compwhiziitothemax's Avatar
    May 2009
    1,276 Posts
    Look into splitting people and projects into different tables.
    Reply With Quote Edit / Delete Reply United States Show Events Agree Agree x 1 (list)

  5. Post #5
    Tezza1234's Avatar
    September 2005
    1,115 Posts

    Not sure if this is what you want / Are looking for?
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Friendly Friendly x 1 (list)

  6. Post #6
    cas97's Avatar
    August 2009
    987 Posts
    so I'd have
    [ id | id_of_person | type | etc ]
    [ id | firstName | lastName | etc ]

    and id_of_person goes to id in people
    I remember doing something like this for a different thing a long time ago


    or just use distinct. thanks!