[FX.php List] 2 value Lists together help
Steve Winter
steve at bluecrocodile.co.nz
Fri Oct 12 09:39:44 MDT 2007
Opps... just spotted a typo there, and that font has done weird things to
the ‘ and “ try this;
First code block from below should be
$contacts = array();
foreach($contactAreas['data'] as $contact)
array_push($contacts, $contact[‘area’][0]);
foreach($VLAreas['data'] as $area) {
echo '<p><input type="checkbox" name="contact[]" value="'.$area.'"';
if(in_array($area,$contacts)) echo ' checked="checked"';
echo '>'.$area.'</p>';
}
Second code block, for the receiving page;
$contacts = array();
foreach($contactAreas['data'] as $key => $contact)
$contacts[$key] = $contact['area'][0];
foreach($_REQUEST['area'] as $area) {
if(!in_array($area,$contacts)) {
// this means that a new area has been checked
// create a new record
}
}
foreach($contacts as $contactKey => $contactValue) {
if(!in_array($contactValue,$_REQUEST['areas'])) {
// this means that the box has been unchecked
// so use $contactKey to delete the record
}
}
_____
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Steve Winter
Sent: Friday, 12 October 2007 4:29 p.m.
To: 'FX.php Discussion List'
Subject: RE: [FX.php List] 2 value Lists together help
Hi William,
Okay, I'll play... I think I understand what you want to do, with the first
part of your query, then we’ll see if I get that right, and then I’ll have a
go at the second part...
I assume that the values returned by the contactAreas search will be a
subset of the records in the VLAreas table...? If that’s correct, this is
what I’d do...
$contacts = array();
foreach($contactAreas[‘data’] as $contact)
array_push($contacts, $contact[‘area’][0])
foreach($VLAreas[‘data’] as $area) {
echo ‘<p><input type=”checkbox” name=”area[]” value=”’.$area.’”’;
if(in_array($area,$contacts)) echo ‘ checked=”checked”’;
echo ‘>’.$item.’</p>’;
Which should give you a checkbox for all of the records in VLAreas, with
those checkboxes for which there is a record in contactAreas...
Now what you need to do is post the data back to FMP... I’d pass the parent
ID in the form that you send...
When you post the data back to the receiving page you should end up with an
array called contact, which has the values which have been checked in it...
What I would then do is re-perform your initial search, and create an array
of the records from contactAreas which has the –recID as the key and the
area as the value, so;
$contacts = array();
foreach($contactAreas[‘data’] as $key => $contact)
$contacts[$key] = $contact[‘area’][0];
Then I’d loop through my posted array and see if the record already
exists... if it does, then that’s great, if not add it...
foreach($_REQUEST[‘area’] as $area) {
if(!in_array($area,$contacts)) {
// this means that a new area has been checked
// create a new record
}
}
Now you need to do the opposite and find out if any have been unchecked...
foreach($contacts as $contactKey => $contactValue) {
if(!in_array($contactValue,$_REQUEST[‘areas’])) {
// this means that the box has been unchecked
// so use $contactKey to delete the record
}
}
Hope this makes sense... not tested, but looks solid to me...
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: Friday, 12 October 2007 3:56 p.m.
To: FX.php Discussion List
Subject: [FX.php List] 2 value Lists together help
Hi Guys,
A quick question (OK, I say quick but that word means different things
to different people)
I run the following query on 3 tables in Filemaker.
find the Parent record from Contacts table
find any associated child records from ContactAreas table
find ALL records from VLAreas table
Works fine.
I need to be able to say in PHP - display a checkbox alongside any of
the records from the VLAreas table (I can do that) and if some of the
values from the ContactAreas table matches any of the values from the
VLAreas table, then let the box be checked (sort of like comparing 2
arrays I think)
I then of course have to be able to FMEdit the changes.
Does someone already know how to do this ?
Many kind thanks in advance
William
_______________________________________________
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.14.8/1064 - Release Date: 11/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.14.8/1064 - Release Date: 11/10/2007
3:09 p.m.
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.8/1064 - Release Date: 11/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.14.8/1064 - Release Date: 11/10/2007
3:09 p.m.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20071012/105b0fb1/attachment-0001.html
More information about the FX.php_List
mailing list