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, and 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[''] == //the id var from the account table
$tabledata[''] == // the id var from the billing table
$tabledata[''] == // the id var from the orders table

instead of just the one $tabledata['id'] value from who knows what table...

can anyone help!!??

Who is Participating?
Hamlet081299Connect With a Mentor Commented:
What type of database are you using, MySQL, MSSQL, Oracle, ...?

I think the ideal solution would be to alias each of the fields, but it depends how the dynamic SQL is being built.  Can you give more details of this part of the code?

Generally speaking, unless you actually alias the fields in some way then the first "id" field will be "id" the next one "id_1" and so on.

If you can get you sql to look more like...

select '', '', '',
  billing.address 'billing.address', ''
  account, billing, orders

... then your problems will be solved.

Depending on your database being used, you can probably extract the necessary field names to build the SQL like this.
christopher sagayamCommented:
how about having something like

n1875621Author Commented:
no... because the information need to be serialized into an array and I cant tell what "$tablename" is from the sql query...
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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]&nbsp;";

// 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.


n1875621Author Commented:
thats fine, except i am not sure what tables are being selected and in what order... its a dynamic sql query....

any ideas?
n1875621Author Commented:
that worked fine.... not exactly what i needed but the pricipal was there...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.