Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    16

    Unanswered: accessing data in array's

    I posted a query question in the mysql forum, and after I got help with the query, I'm now trying to access the query results...

    Here are the 2 tables...

    Code:
    units_main:
    FACID----sub_key-----ASGMT_Name
    AR01____1000_______LEGAL COMMAND
    AR01____1001_______OPPS 67
    AR02____1002_______REG D
    
    
    units_sub:
    FACID-----sub_key-----Long_Name
    AR01_____1000_______cmd a, b and sometimes c
    AR01_____1000_______secondary cmd structrue
    AR01_____1001_______opps seg 798 b
    AR02_____1002_______s cmd structure cc8
    Here's what i have so far...

    Code:
    $real_facid = $_SESSION['facid'];
    
    $query = "SELECT m.FACID
     , m.sub_key
     , m.ASGMT_Name
     , s.Long_Name
    FROM units_main AS m
    LEFT OUTER
    JOIN units_sub AS s
    ON s.FACID = m.FACID
    AND s.sub_key = m.sub_key
    WHERE m.FACID = '$real_facid'
    ORDER
    BY m.FACID
    , m.sub_key
    , s.Long_Name";
    
    
    $result = mysql_query($query) or die(mysql_error());
    
    $res = array();
    while ($rows = mysql_fetch_array($result))
    { 
        if (!array_key_exists($res, $rows['ASGMT_Name']))
                {
                    $res[$rows['ASGMT_Name']] = array();
                }
                $values = $res[$rows['ASGMT_Name']];
                array_push($values,$rows['Long_Name']);
    }
    foreach($res as $key => $value )
    {
            echo "$key<br>";
            echo "$value<br>";
    }
    Here's the output...

    Code:
    Here's the output:
    LEGAL COMMAND
    Array
    OPPS 67
    Array
    The units_sub.Long_Name is just displayed as "Array"? How do I access this Array?

    thanks!

  2. #2
    Join Date
    Dec 2011
    Posts
    1
    You can access as a normal array, with other loop

  3. #3
    Join Date
    Nov 2011
    Posts
    16
    Quote Originally Posted by blackmouse1900 View Post
    You can access as a normal array, with other loop
    got it...loop within a loop. thanks!

Posting Permissions

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