array problem...
| From: | Matthew Ferry | Date: | Sun, 10 Dec 2006 14:54:59 +0000 |
| Subject: | array problem... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-42808@lists.php.net to get a copy of this message | ||
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.
Code for that:
<?php
$db = mysql_connect("HOST", "USERNAME", "PASSWORD");
mysql_select_db("DATABASE",$db);
$result = mysql_query("SELECT * FROM egw_addressbook
WHERE cat_id=10", $db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=0>\n";
echo "<img src=file.jpg width="939" height="136">\n";
echo "<BR>\n";
echo "<BR>\n";
echo "<BR>\n";
echo "<BR>\n";
echo "<BR>\n";
do {
printf("<tr>
<td></td><td><b>%s</b></td><td></td><td></td><td></td><td>%s
%s</td></tr>\n", $myrow["org_name"], $myrow["n_given"],
$myrow["n_family"]);
printf("<tr> <td></td><td>%s</td><td>
</td><td></td><td></td><td>%s</td></tr>\n",
$myrow["adr_one_street"], $myrow["tel_work"]);
printf("<tr> <td></td><td>%s, %s
%s</td><td></td><td></td><td></td><td></td></tr>\n",
$myrow["adr_one_locality"], $myrow["adr_one_region"],
$myrow["adr_one_postalcode"]);
printf("<tr>
<td></td><td></td><td></td><td></td><td></td><td></td></tr>\n");
printf("<tr>
<td></td><td></td><td></td><td></td><td></td><td></td></tr>\n");
printf("<tr>
<td></td><td></td><td></td><td></td><td></td><td></td></tr>\n");
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "Sorry, no records were found!";
}
?>
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.
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="Supplier" and contact_id="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