array problem...

array problem...

am 10.12.2006 15:54:59 von Matthew Ferry

------=_NextPart_000_0015_01C71C41.40E3A060
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello everyone,

I'm new to PHP/MySQL but I know my way around good now.

I have egroupware installed/setup and its running fine. I want to =
create a couple of PHP pages that access the mySQL data to report the =
info in egroupware. The information in the one table I can access fine. =
=20

Code for that: =20


$db =3D mysql_connect("HOST", "USERNAME", "PASSWORD");

mysql_select_db("DATABASE",$db);

$result =3D mysql_query("SELECT * FROM egw_addressbook

WHERE cat_id=3D10", $db);

if ($myrow =3D mysql_fetch_array($result)) {

echo "

\n";

echo "\n";

echo "
\n";

echo "
\n";

echo "
\n";

echo "
\n";

echo "
\n";

do {

printf(" =
\n", $myrow["org_name"], $myrow["n_given"], =
$myrow["n_family"]);

printf("\n", $myrow["adr_one_street"], =
$myrow["tel_work"]);

printf("\n", =
$myrow["adr_one_locality"], $myrow["adr_one_region"], =
$myrow["adr_one_postalcode"]);

printf(" =
\n");

printf(" =
\n");

printf(" =
\n");

} while ($myrow =3D mysql_fetch_array($result));

echo "
%s%s =
%s
%s =
%s
%s, %s =
%s
\n";

} else {

echo "Sorry, no records were found!";=20

}

?>



For what you see there. It works Great. BUT

There is other info in another table I want to report also in this page. =
In the second table one record may have more than one row. It stays =
associated with the correct contact with the "contact_id" column matches =
the "id" column from the first table. This second table is used for =
custom fields in egroupware. =20



So to do a search for a record in the second table. its something like:

SELECT contact_value FROM egw_addressbook_extra
WHERE contact_name=3D"Supplier" and contact_id=3D"correct number from =
first table"

Also valid for Contact_name are: RANO, Install Date, PrevSystem



When I build the top array I want to include these four other fields but =
they have to be with the correct record from the first table.



Do I want to do a array merge?

Can I add some ANDs to my current SELECT statement?



I have tried a bunch of stuff can't find a solution.

The bottom line is have it create the array from the first table and =
then add 4 columns on the end. then pull the info from the second table =
and insert it in the last 4 column of the array





Thanks...



Matt




------=_NextPart_000_0015_01C71C41.40E3A060--

Re: array problem...

am 10.12.2006 16:06:09 von Niel Archer

Hi

sounds like you should be doing a JOIN on the tables to get what you
want

SELECT * FROM table1 LEFT JOIN table2 ON id = contact_id WHERE cat_id=10

then use a loop to retrieve/print each row, ignoring the duplicated data
on the 2nd and successive iterations

Niel

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php