[FX.php List] Posting an array help

Joel Shapiro jsfmp at earthlink.net
Mon Oct 22 13:10:05 MDT 2007


Has anybody used things like array_diff()?
http://us2.php.net/manual/en/function.array-diff.php

The top User Note seems to point to something that might be relevant  
for William's situation.

(I'd been looking into this and related array functions just last  
week, but couldn't find anything that would easily compare various  
sub-arrays, so I ended up looping through the arrays afterall)

-Joel


On Oct 22, 2007, at 8:39 AM, Steve Winter wrote:

> Hi William,
>
> Umm, to my knowledge you can't use in_array to compare two arrays,  
> you need
> to loop through one of the arrays, and check the values of that  
> array, in
> the other, and then visa versa (at least that's what I'd do)
>
> My approach would be;
>
> foreach($v1AoE as $vlValue) {
>   if(!in_array($v1Value, $medAoEData)) {
>     // this means that it's in the posted array but not in the db
>     // FMNew() time
>   }
> }
>
> foreach($medAoEData as $medValue) {
>   if(!in_array($medValue, $v1AoE)) {
>     // this means that it's in the db but not the posted array
>     // FMDelete() time
>   }
> }
>
> Be interested to hear how others would approach this to...
>
> Cheers
> Steve
>
> -----Original Message-----
> From: fx.php_list-bounces at mail.iviking.org
> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of William  
> Downs
> Sent: Monday, 22 October 2007 4:28 p.m.
> To: FX.php Discussion List
> Subject: [FX.php List] Posting an array help
>
> Hi there guys,
>
> Headbanging the key board now ! Perhaps someone has already done this.
>
> The user selects a record - this record has child records.
> I allow the user to check box select any number of child records.
> I then POST the array to the next page
> The next page runs an FMFind for the original DB values
>
> if there are new values in the POSTed array, they should be created
> (FMNew) in the child table
> If they are not in the POSTed array, it means that they have been
> deselected, and should be deleted in the child table.
>
> Here is where it falls flat - ($vlAoE is the POSTed array and
> $medAoEData is the array from the DB)
>
> if(!in_array($vlAoE,$medAoEData)) {
>                //It should  create the new values here
> } else {
>              if(!in_array($medAoEData, $vlAoE,)) {
>                //It should delete the old values here
> }
> }
>
> Probably obvious what I have done wrong - but any advice more than
> appreciated.
>
> Regards
>
> William
>
> -- 
> William Downs
> Development and Support
> BD Databases Ltd
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.488 / Virus Database: 269.15.5/1084 - Release Date:  
> 21/10/2007
> 3:09 p.m.
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.488 / Virus Database: 269.15.5/1084 - Release Date:  
> 21/10/2007
> 3:09 p.m.
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



More information about the FX.php_List mailing list