[FX.php List] Conditional value lists with PHP and FileMaker

Joel Shapiro jsfmp at earthlink.net
Wed Nov 19 15:39:06 MST 2008


Hi Anders

I'm not surprised I had a couple glitches in my emailed code...  ;-)   
Glad you got it working for you.

If the Dist numbers ARE unique, and the Dist names are variations of  
the same thing (e.g. "ISD" vs. "The ISD"), and it doesn't really  
matter to you which variation of the Name you use, then you could go  
back to sort by Number and change to $distNum instead of $distName  
for your if() clause.  If you DO need to use a specific version of  
the Name, then that's a data issue that would need to be dealt with  
within the DB.

Note that sorting by number would remove the alphabetical order of  
the dropdown, but you could do sorting within the PHP if that were  
important to you.

-Joel


On Nov 19, 2008, at 2:16 PM, Anders Monsen wrote:

> Joel,
>
> After bringing in your text I now have the dropdown appearing in  
> the SESSION. I had to make two small changes to your code ( you had  
> an extra semi-colon in this line: if ($distName != $distData 
> ['District name'];) { --- and the $distData['dist_Num'] needed to  
> be $distData['dist_Num'][0] ). Otherwise this is extremely useful  
> code.
>
> However, because the values are not unique in the table, the value  
> list is showing up with multiple values for the same district. I  
> may need to see if I can get the FileMaker database re-structured  
> to eliminate the duplicate values in the current table. I think the  
> complicated way I created the array previously filtered it for  
> unique values only.
>
> Thanks,
> Anders
>
>
> On Nov 19, 2008, at 3:41 PM, Anders Monsen wrote:
>
>> Hi Joel,
>>
>> Thanks for your comments. I should have posted my dilemma before  
>> spending all that time on the code...
>>
>> And, after reading through  a couple of times what you wrote  
>> below, I realize that I way over-complicated things. I approached  
>> it form the wrong direction, thinking I needed to build the array  
>> to contain the values from scratch, instead of using the  
>> $distResult['data'] array that I already have. Truly a Doh! moment  
>> on my part.
>>
>> I like the Ajax option, and I've created a proof of concept from  
>> Jonathan Stark's article that works great. I also like the session  
>> array idea that you and GGT suggest. If I can combine these pieces  
>> I should end up with a more streamlined process.
>>
>> Anders
>>
>> On Nov 19, 2008, at 3:13 PM, Joel Shapiro wrote:
>>
>>> Hi Anders
>>>
>>> I might not be understanding something here, because it doesn't  
>>> seem like it should be so complicated.  I'm assuming that there  
>>> is a one-to-one correspondence between District Name & Number.   
>>> This is what I'd do:
>>>
>>> Sort the Districts by name (so that the drop-down displays in  
>>> alphabetical order), then something like:
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> if ( !isset($_SESSION['distDropdown'] ) ) {
>>> 	
>>> 	// If distDropdown is not yet created, find and process the 300  
>>> records
>>> 	// This way you only need to do this the first time the page is  
>>> loaded
>>>
>>> 	// Perform Find Here
>>> 	// same query as you currently have,
>>> 	// but I'd sort by Dist name so dropdown is in alpha order
>>> 	
>>> 	$distName = '';
>>>
>>> 	$_SESSION['distDropdown'] = '<select name="dist"  
>>> onchange="this.form.submit()">'. "\n";
>>>
>>> 	foreach ($distResult['data'] as $key => $distData) {
>>>
>>> 		if ($distName != $distData['District name'];) {
>>> 			$_SESSION['distDropdown'] .= '<option value="'. $distData 
>>> ['dist_Num'] .'">' . $distData['District name'] . '</option>'."\n";
>>> 		}
>>>
>>> 		$distName = $distData['District name'];
>>>
>>> 	}
>>>
>>> 	$_SESSION['distDropdown'] .= '</select>';
>>> 	
>>> }
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> To display the dropdown in the form, it's just a simple:
>>> echo $_SESSION['distDropdown'];
>>>
>>> Then the submission of this form (via a selection from the  
>>> dropdown) would perform a new query of Campuses based on the  
>>> dist_Num selected.  This form submission would be great for AJAX,  
>>> but a regular form submission and a full-page reload shouldn't be  
>>> so bad since you don't need to find and compile the distDropdown  
>>> again.
>>>
>>> etc.
>>>
>>> Or am I missing something?
>>>
>>> HTH,
>>> -Joel
>>>
>>>
>>> On Nov 19, 2008, at 8:46 AM, Anders Monsen wrote:
>>>
>>>> Has anyone on the list worked on this issue? I spent most of  
>>>> yesterday putting together a process that works, but may not be  
>>>> the most efficient process. I was wondering if anyone would be  
>>>> open to looking at my code (the snippet is 130 lines long at  
>>>> minimum, so I didn't just want to throw it out there) to see if  
>>>> there are ways I can improve the process. It certainly made me  
>>>> appreciate how easy FileMaker makes this process...
>>>>
>>>> (I just discovered and read Jonathan Stark's article in July  
>>>> FileMakerAdvisor after writing this email. It uses Ajax, so I  
>>>> may try to incorporate his techniques, although I'm using FX.php  
>>>> and no existing value lists from FileMaker, just existing data.)
>>>>
>>>> Here's the scenario. I have a table with four fields: district  
>>>> number, district name, campus number, and campus name. I want  
>>>> the district and campus to be drop down menus, where the user  
>>>> sees the name but submits the number into another FileMaker  
>>>> database/table. Also, when the user selects a district, I need  
>>>> the value list of campuses to correspond just to their  
>>>> appropriate district.
>>>>
>>>> My first issue was to find a way to create an associative array  
>>>> with district numbers=>district names. Apparently I took the  
>>>> hard route in dynamically building associative arrays... After  
>>>> several failed attempts, I used a function that I found on  
>>>> php.net in the section on "array_push" to create this array. The  
>>>> first problem I ran into was that the list currently contains  
>>>> 270 records. For now I had to manually change the groupsize in  
>>>> the query to above 300, but I plan to first query all records to  
>>>> get a count, then make this the groupsize. The reason for this  
>>>> is that the district array becomes unique only after all records  
>>>> have been loaded into the array, so the default groupsize of 50  
>>>> has to be modified.
>>>>
>>>> Is there a way to 1) build a better array and 2) make the  
>>>> district array unique in the initial query? The database is  
>>>> structured as one file, with all four fields, and so the  
>>>> district numbers and names are repeated. I didn't create the  
>>>> database, and I can't change it.
>>>> Distnum	|	Distname	| CampusNum	|	Campus Name
>>>> 10			The ISD		2			School
>>>> 10			The ISD		2.1			OtherSchool
>>>> etc.
>>>>
>>>> Additionally, after several failed attempts to get the  
>>>> Javascript onchange function to work when the form changed, I  
>>>> resorted to DreamWeaver's JumpMenu, which seems to work fine.  
>>>> Has anyone been able to get a working onchange form and what is  
>>>> the correct syntax? When the user selects a district from the  
>>>> dropdown, the page reloads with the district number in the URL.
>>>>
>>>> Given all of the above, my process *does* work, and the page  
>>>> does not appear to load with delays. I have not used conditional  
>>>> values lists with PHP/Javascript in about three years, so I am a  
>>>> little unsure of best practices.
>>>>
>>>> Thanks,
>>>> Anders
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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



More information about the FX.php_List mailing list