[FX.php List] Posting an array help

William Downs william.downs at gmail.com
Tue Oct 23 10:19:08 MDT 2007


Hi Steve and Joel !

After a lot of looking at things like the code below:-

$newvlAoE = $_POST['vlAoE'];

$complete = array_unique(array_merge($medAoEData, $newvlAoE));

which gives me a combined set of unique values, I decided against it all.

Instead of working out what is already present, what should be added
and what should be removed, I decided to simply recreate them all, i.e
delete any found then recreate them from the POSTed array.

As there are no grandchildren type records, it should be OK (unless
anyone can see a problem with that approach ??)

However, the array functions I investigated above were interesting to
learn and will be useful in the future I think,

Many thanks guys, your answers opened my eyes all the same,

Kind Regards,

William

On 10/22/07, William Downs <william.downs at gmail.com> wrote:
> Hi Steve,
>
> I like this idea, I will give it a test tomorrow and let you know how it went,
>
> Many thanks for this,
>
> William
>
> On 10/22/07, Steve Winter <steve at bluecrocodile.co.nz> wrote:
> > Hi Joel,
> >
> > As I understand it array_dif() will tell provide you with an array of the
> > items that are not in both of the two arrays that your feed to it... I'm not
> > really sure how that could be helpful, since it wouldn't be able to tell you
> > which ones to add, or remove...
> >
> > I guess if you did
> >   $difference = array_dif($v1AoE, $medAoEData);
> > Then you could do a foreach($difference as $item) and test against the two
> > arrays, which I guess means that there may be less items to have to loop
> > through if there were not many changes, which may be a little quicker...??
> >
> > How about this for a random, untested idea;
> >   $difference = array_dif($v1AoE, $medAoEData);
> > So now you know which ones must either be added or removed, then
> >   $adds = array_intersect($difference, $v1AoE);
> >   $deletes = array_intersect($difference, $medAoEData);
> > Then you could loop through each of $adds and $deletes
> >   foreach($adds as $add) {
> >     // add this record
> >     // FMNew()
> >   }
> >   foreach($deletes as $delete) {
> >     // add this record
> >     // FMDelete()
> >   }
> >
> > Should work, I guess if there were lots of items in $v1AoE and or
> > $medAoEData, and there were likely to be few changes, then it should also be
> > quicker than two lengthy foreach loops...
> >
> > 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 Joel Shapiro
> > Sent: Monday, 22 October 2007 8:10 p.m.
> > To: FX.php Discussion List
> > Subject: Re: [FX.php List] Posting an array help
> >
> > 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
> >
> > _______________________________________________
> > 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
> >
>
>
> --
> William Downs
> Development and Support
> BD Databases Ltd
>


-- 
William Downs
Development and Support
BD Databases Ltd


More information about the FX.php_List mailing list