Help building a simple array

Discussion in 'PHP' started by phelixx, Jun 30, 2011.

  1. #1
    This is how I am making my array; But it appears that this array is only grabbing the data from the last row. How can I get $theinfo to store the data from all the rows?


    $query1 = "SELECT t1.* FROM profile_values AS t1 INNER JOIN profile_values AS t2 USING (uid) WHERE t2.fid=4 AND t2.`value`='1' AND t1.fid!=4";
    $q1 = mysql_query($query1);
    while($res1 = mysql_fetch_array($q1)){

    $theinfo[$res1['fid']] = $res1['value'];
    }
     
    phelixx, Jun 30, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    If the fid column is unique, it should. If it's not, you'll have to use a unique column for the array key, or just increment it.

    i.e.
    $theinfo[$res['unique_column']] = $res1['value'];
    Code (markup):
    or:
    $theinfo[] = $res1['value'];
    Code (markup):
     
    Alex Roxon, Jun 30, 2011 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Why would you make an array of a database result. You normally need to loop through the array to get the values. This is redundant and creates unnecessary overhead.
     
    jestep, Jul 1, 2011 IP