Chris W. Parker wrote:
Hey peeps.
Let me make this simple. I've got the following sql query in a function:
SELECT c.id
, cc.id
, cc.prod_id
, p.name
, cc.price
, cc.qty
FROM cart AS c
INNER JOIN cart_contents AS cc
ON cc.cart_id = c.id
INNER JOIN products AS p
ON p.id = cc.prod_id
WHERE c.cust_id = '6'
ORDER BY cc.id
When I get the result and turn it into an array with
mysql_fetch_array($var, MYSQL_BOTH) I see the following with print_r():
Array
(
[0] = Array
(
[0] = 2
[id] = 3
[1] = 3
[2] = SDG6004-XX-XXX
[prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[name] = Model 6004
[4] = 89.00
[price] = 89.00
[5] = 2
[qty] = 2
)
)
Notice that index 1 does not have a textual companion like the other
indexes do. I expected the array to be created like this:
Array
(
[0] = Array
(
[0] = 2
[c.id] = 3
[1] = 3
[cc.id] = 3
[2] = SDG6004-XX-XXX
[cc.prod_id] = SDG6004-XX-XXX
[3] = Model 6004
[p.name] = Model 6004
[4] = 89.00
[cc.price] = 89.00
[5] = 2
[cc.qty] = 2
)
)
But alas... that's not how it works.
Anyway to get what I want?
Thanks,
Chris.
As you can see only column names create indexes, not table_name dot
column_name. And thus your second id (cc.id) overwrites the first one (c.id)
You can make the query:
SELECT c.id
, cc.id AS ccid
, cc.prod_id
, p.name
and you will get $row['id'] and $row['ccid']
Marek
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php