array intersect with 2 arrays created from mysql
| From: | Nigel Dunn | Date: | Tue, 08 Oct 2002 03:21:42 +0000 |
| Subject: | array intersect with 2 arrays created from mysql | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22268@lists.php.net to get a copy of this message | ||
Hi,
If anyone can help me with this I'd be most appreciative.
I'm constructing 2 arrays of IDs from 2 different tables. Then I want to compare one to the other and only use the results that both arrays share in common to do a query loop that pulls the information for the related IDs to display.
The error I get from the code below is:
Warning: Argument #2 to array_intersect() is not an array in /usr/local/www/vhosts/trustbuild.co.nz/htdocs/partners_region.php on line 185
I cant see what is causing the problem.
<<< Start of My Existing Code >>>
$result = mysql_query("SELECT partner_id FROM partner_region WHERE region_id = '$r' ORDER BY partner_id");
if ($row = mysql_fetch_array($result)) {
do {
partner_region[] = $row['partner_id'];} while ($row = mysql_fetch_array($result)); } if (count($partner_region) != 0) { array_unique($partner_region); } $result2 = mysql_query("SELECT id FROM partner WHERE type = '$t' ORDER BY id"); if ($row2 = mysql_fetch_array($result2)) { do {
partner_type[] = $row2['id'];} while ($row2 = mysql_fetch_array($result2)); } if (count($partner_type) != 0) { array_unique($partner_type); } $partner = array_intersect($partner_region, $partner_type); if (count($partner) != 0) { foreach ($partner as $p) {
$result3 = mysql_query("SELECT * FROM partner WHERE id = '$p'");
if ($row3 = mysql_fetch_array($result3)) {
do {
$company_name = $row3['company_name'];
$contact_name = $row3['contact_name'];
$physical_address = $row3['physical_address'];
$postal_address = $row3['postal_address'];
$city = $row3['city'];
$phone = $row3['phone'];
$fax = $row3['fax'];
$email = $row3['email'];
$url = $row3['url'];
$gst_number = $row3['gst_number'];
$company_age = $row3['company_age'];
$services = $row3['services'];
$region = region($r);
if ($count == 0) {
echo "<tr><td bgcolor='#FFFFFF'><a href='closeup.php?id=$id'>$region $company_name</a><br>Type: $company_type<br>Contact Name: $contact_name<br>".nl2br($physical_address)."</td></tr>";
$count++;
} else {
echo "<tr><td bgcolor='#DDDDDD'><a href='closeup.php?id=$id'>$region $company_name</a><br>Type: $company_type<br>Contact Name: $contact_name<br>".nl2br($physical_address)."</td></tr>";
$count--;
}
} while ($row3 = mysql_fetch_array($result3));
}
}
} else {
echo "There are no listings for your criteria. Please try again.<br>";
}
<<< End of My Existing Code >>>
Thanks in advance for any help with this one,
Nigel Dunn