If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > accessing data in array's

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-19-11, 08:33
dbecker88 dbecker88 is offline
Registered User
 
Join Date: Nov 2011
Posts: 16
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!
Reply With Quote
  #2 (permalink)  
Old 12-28-11, 13:42
blackmouse1900 blackmouse1900 is offline
Registered User
 
Join Date: Dec 2011
Posts: 1
You can access as a normal array, with other loop
Reply With Quote
  #3 (permalink)  
Old 01-05-12, 10:29
dbecker88 dbecker88 is offline
Registered User
 
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On