Re: Problem with using array_diff and array_combine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Kurth wrote:
> I hope I can explain what I am trying to do.
> I have two tables the first one has the custom form elements
> 
> 
> elements_id elements_field_type elements_field_caption members_id
>       35       text                      test                8
>       36       text                      test2                8
> 
> 
> The second one has the customer id and the field value withe the field name
> 
> dbelements_field_name     dbelements_field_value     members_id customer_id
>           35                Test This Field          8           346
>           36                                          8           346
>           36                Test2                  8           347
> 
> 
> If you look at the second table you will see that one field name is
> related to two different  customers and one field name on relates to one
> customer.
> I am trying to look at these two tables and find customer that do not
> have a row for each field name.
> 
> I have been trying with
> 
> array_combine($dbelements_field_array,$dbelements_id_array)
> and also array_diff($customf_array,$dbelements_field_array)

You can do it in sql.

// find customer_id's who don't have all fields filled in
$subquery = "
select
  customer_id
from
  customformelements cfe
left join
  dbelements de on (cfe.elements_id=de.dbelements_field_name and
de.members_id=cfe.members_id)
where
  cfe.members_id=8
and
de.dbelements_field_name is null
";

Then get your customers:

select
  c.*
from
  contacts
where
  customer_id in
(
  $subquery
);


Also for array_diff you have to check it both ways:

$ cat diff.php
<?php

$array_one = array (1,2,3,4,5);
$array_two = array (2,3,4);

$diff_one = array_diff($array_one, $array_two);
echo "diff 1:\n";
print_r($diff_one);

$diff_two = array_diff($array_two, $array_one);
echo "diff 2:\n";
print_r($diff_two);


$ php diff.php
diff 1:
Array
(
    [0] => 1
    [4] => 5
)
diff 2:
Array
(
)


-- 
Postgresql & php tutorials
http://www.designmagick.com/

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux