Re: 2 queries --> 1 array
| From: | Matthew Ferry | Date: | Fri, 12 Jan 2007 20:48:36 +0000 |
| Subject: | Re: 2 queries --> 1 array | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42942@lists.php.net to get a copy of this message | ||
I tried a buch of JOINs, but with no luck
The problem comes in with I have to do a different query for each contact_name values for every
record.
SELECT contact_value FROM egw_addressbook_extra WHERE contact_name='Supplier' and
contact_id=' 1'
SELECT contact_value FROM egw_addressbook_extra WHERE contact_name='RANO' and
contact_id=' 1'
SELECT contact_value FROM egw_addressbook_extra WHERE contact_name='PrevSystem' and
contact_id=' 1'
SELECT contact_value FROM egw_addressbook_extra WHERE contact_name='Dynamic' and
contact_id=' 1'
Then add those values to the array created from query of the first table
Thanks...
Matt
----- Original Message -----
From: Natalie Leotta
To: Matthew Ferry
Sent: Friday, January 12, 2007 3:41 PM
Subject: Re: [PHP-DB] 2 queries --> 1 array
I think this will help, but I'm not sure I understood your question correctly.
http://www.w3schools.com/sql/sql_join.asp
On 1/12/07, Matthew Ferry <mferry@retailautomation.biz> wrote:
Hello,
I need to query two different tables and create one "BIG" array.
I can query both tables, but can't find a way to combine the results in one array.
The problem comes in with the second table. It has a weird layout.
The second table only has four fields. They are: contact_id, contact_owner, contact_name, and
contact_value
a.. The 'contact_id' needs to be linked to 'id' field from the first
table.
b.. The contact_name is a field I need to use to reference what i'm looking for.
example... contact_name HAS values of RANO, PrevSys, Supplier, Dynamic
each of them has the same contact_id different contact_names with different
contact_values
To query the second table I do something like this:
SELECT contact_value FROM egw_addressbook_extra WHERE contact_name='Supplier' and
contact_id=' XXX'
The xxx is the ID from the first table.
-----------------------------------------
Table 1:
ID NAME BUSINESS ADDRESS
CITY PHONE
1 John Smith Smith's Phone Co. 100 Main St
Someplace 555-5555
2 Joe Brown Brown's Shoe Store 105 Grant St.
This City 555-0001
Table 2:
CONTACT_ID CONTACT_NAME
CONTACT_VALUE CONTACT_OWNER
1 PrevSys
NONE 4
1 RANO
100102 4
1 Supplier
TrueValue 4
1 Dynamic
192.168.0.0 4
2 PrevSys
OLD POS SYS 4
2 RANO
100105 4
2 Supplier
Orgill 4
2 Dynamic
192.168.100.0 4
I want to query both tables and create a array. The extra fields from table two need to have
their own field in the array.
I need to call those extra fields in the array by the contact_name field...
example.... $myrow[supplier] $myrow[PrepSys] $myrow[name]
I have tried alot of stuff to get this done, but i think i was very off task.
Some help/guide is needed.... I'm new!!!!
Thanks...
Matt