?
Solved

php and postgres quessie.....

Posted on 2002-06-02
6
Medium Priority
?
276 Views
Last Modified: 2006-11-17
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!!??


0
Comment
Question by:n1875621
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 7050759
how about having something like

$tabledata[$tablename][$id];
0
 

Author Comment

by:n1875621
ID: 7050787
no... because the information need to be serialized into an array and I cant tell what "$tablename" is from the sql query...
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7051004
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.

JD


0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 

Author Comment

by:n1875621
ID: 7052339
thats fine, except i am not sure what tables are being selected and in what order... its a dynamic sql query....

any ideas?
0
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 400 total points
ID: 7052649
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
  account.id 'account.id',
  account.name 'account.name',
  billing.id 'billing.id',
  billing.address 'billing.address',
  orders.id 'orders.id'
  ...
from
  account, billing, orders
where.....

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

Author Comment

by:n1875621
ID: 7052657
that worked fine.... not exactly what i needed but the pricipal was there...

cheers
john
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question