|
\./
 .

Aaron Wolski wrote:
> *** Sorry if this is a duplicate for some on another list**
> 
> Hi Guys,
> 
> I need help with this code I am about to paste. It works on a
> testing server running PHP 4.2.2 but not 4.3.2
> 
> Here is the error:
> 
> Warning: array_merge_recursive(): recursion detected in
> /services2/webpages/r/i/rinkrake.com/public/test.php on line 26
> 
> Here is the code:
> 
> <?php
> echo "Generating results, this could take a minute....<br>";
> // Allow the script enough time to finish (lots of data, lots
> of loops) set_time_limit(999);
> 
> // db connection
> $link = mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx");
> 
> // We need these queries to do our job
> $we_ordered_1 = mysql_query("select OrderTable.cart_id,
> CartTable.cart_id, CartTable.product_index from OrderTable,
> CartTable where CartTable.product_index = 1 and
> OrderTable.cart_id = CartTable.cart_id");
> 
> $we_ordered_14 = mysql_query("select OrderTable.cart_id,
> CartTable.cart_id, CartTable.product_index from OrderTable,
> CartTable where CartTable.product_index = 14 and
> OrderTable.cart_id = CartTable.cart_id");
> 
> $customers = mysql_query("select cart_id, first, last, email
> from OrderTable");
> 
> // Compare cart_id's between customers who ordered product #1 and
> #14. If the customer // ordered #1 and not #14, put their cart_id in
> the $good_customers array and move on // to the next.
> while ($row1 = mysql_fetch_row($we_ordered_1))
>             {
>             while ($row2 = mysql_fetch_row($we_ordered_14))          
>                         { if ($row1[0] != $row2[0])
>                                     {
>                                     $temp[cust_id] = $row1[1];
>                                     $good_customers =
> array_merge_recursive($good_customers,$temp);
>                                     }
>                         }
>             mysql_data_seek($we_ordered_14,0);
>             }
> 
> // Free up some memory, reset things back to square one (just
> to be on the safe side) // and get rid of any duplicate items
> in our newly created array.
> mysql_free_result($we_ordered_1);
> mysql_free_result($we_ordered_14);
> unset ($temp);
> reset ($good_customers);
> $good_customers = array_unique($good_customers[cust_id]);
> 
> // Fetch a customer, step through the $good_customers array
> and // compare the cart_id stored in $good_customers, if they
> match, // kick out a 'record' with the necessary data.
> while ($row3 = mysql_fetch_row($customers))
>             {
>             foreach ($good_customers as $value)
>                         {
>                         if ($row3[0] == $value)
>                                     {
>                                     echo $row3[0]." |
> ".$row3[1]." | ".$row3[2]." | ".$row3[3]."<br>\n";
>                                     }
>                         }
>             }
> mysql_close($link);
> echo "<script language=JavaScript>alert(\"Done!\");</script>";
>> 
> 
> CAN anyone help me resolve the problem? I know it has to do
> with a bug being fixed for array_merge_recursive but I don't
> know how to resolve the problem and get the results I need :-(
> 
> Please help?
> 
> Thanks so much!!!
> 
> Aaron

Am not sure about the bug in yout script, but what are you trying to do? For
what I understand you are trying to find all customers who ordered Product
ID #1 and not Product ID #14? If that's right, simply fire:

<?php
$Orders = mysql_query('SELECT *
FROM OrderTable LEFT JOIN CartTable on OrderTable.cart_id =
CartTable.cart_id
WHERE CartTable.product_index IN (1,14)
ORDER BY product_index ASC');

$Ones           = Array();
while($Order = mysql_fetch_assoc($Orders)) {
        if ($Order['product_index'] == 1) {
                $Ones['cart_id'] = Array($Order);
        } elseif {
                ($Order['product_index'] == 14) unset($Ones['cart_id']; 
        }
}
?>

This will leave you with an array "$Ones" with all returned rows where the
cusomer ordered #1 and not #14. The trick is that I ordered on
product_index, so that I am sure that I'm processing all 1's first, and then
all 14's. With some more advanced order by tricks (this one's pretty simple)
you can probably leave out the enire where clause, and getting entire orders
matching the criteria you set. 

Hope it helped you ;)
Wouter

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

Reply via email to