n1875621
asked on
php and postgres quessie.....
i have an sql command like...
select account.* billing.* orders.* from account, billing, orders WHERE.....
and I am putting the results of this query into a serialized php array... like so.....
for($i=0; $row = @pg_fetch_array($res,$i); $i++)
{
$tabledata = $row;
}
however, i am getting undesired results because the tables have common column names, for example, accounts.id order.id and billing.id and yet my $tabledata variable just has the on $tabledata["id"] element...
what i need (and i am not sure if its at a php level or sql level) is something which will allow me to have an array indexed by tablename.columnname rather than just column name...
so for the above example i would have
$tabledata['accounts.id'] == //the id var from the account table
$tabledata['billing.id'] == // the id var from the billing table
$tabledata['orders.id'] == // the id var from the orders table
instead of just the one $tabledata['id'] value from who knows what table...
can anyone help!!??
select account.* billing.* orders.* from account, billing, orders WHERE.....
and I am putting the results of this query into a serialized php array... like so.....
for($i=0; $row = @pg_fetch_array($res,$i); $i++)
{
$tabledata = $row;
}
however, i am getting undesired results because the tables have common column names, for example, accounts.id order.id and billing.id and yet my $tabledata variable just has the on $tabledata["id"] element...
what i need (and i am not sure if its at a php level or sql level) is something which will allow me to have an array indexed by tablename.columnname rather than just column name...
so for the above example i would have
$tabledata['accounts.id'] == //the id var from the account table
$tabledata['billing.id'] == // the id var from the billing table
$tabledata['orders.id'] == // the id var from the orders table
instead of just the one $tabledata['id'] value from who knows what table...
can anyone help!!??
ASKER
no... because the information need to be serialized into an array and I cant tell what "$tablename" is from the sql query...
In that case you should go for pg_fetch_row.
$result = pg_Exec($conn,"select account.*,billing.*,order. * from ....");
$num = pg_numrows($result);
for ($i=0; $i < $num; $i++)
{
$r = pg_fetch_row($result, $i);
for ($j=0; $j < count($r); $j++) {
echo "$r[$j] ";
}
// the fields would be in the same order as in table and between tables it would be in same order as you have wrote table names.
JD
$result = pg_Exec($conn,"select account.*,billing.*,order.
$num = pg_numrows($result);
for ($i=0; $i < $num; $i++)
{
$r = pg_fetch_row($result, $i);
for ($j=0; $j < count($r); $j++) {
echo "$r[$j] ";
}
// the fields would be in the same order as in table and between tables it would be in same order as you have wrote table names.
JD
ASKER
thats fine, except i am not sure what tables are being selected and in what order... its a dynamic sql query....
any ideas?
any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that worked fine.... not exactly what i needed but the pricipal was there...
cheers
john
cheers
john
$tabledata[$tablename][$id