[FX.php List] Re: Suppressing zero values and sorting an array

Salvador A. Sandoval sal at nambetech.net
Sat Aug 2 12:53:46 MDT 2008


The code bellow sorts by OptionName and suppresses zero  OptionCost
values:

 

 

<?php

        $events_list = "";

        if (array_key_exists('Choice',$_POST)) {

               foreach($_POST['Choice'] as $choice) {

               $parent_event_id = substr($choice,0,strpos($choice," -
"));

               $event_name = substr($choice,strpos($choice," - ") + 3);

 

               $Options = new FX(FMIP, FMWCPort);

               $Options->SetDBData(Database, 'EventOptions');

               $Options->SetDBUserPass(User,Password);

               $Options->AddDBParam('ActiveCalc', "Active");

               $Options->AddDBParam('EventRecordID', $parent_event_id);

               $OptionsData = $Options->FMFind();

               

               $events_list .= "<input type=\"hidden\" name=\"EventID\"
value=\"".$parent_event_id."\">";

               

               if ($OptionsData['foundCount'] > 0) {

                       $events_list .= "<B>" . $event_name .
"</B><hr><br>";

                       

                       // Place returned options in an associative
arrays using OptionName as key.  Thus allowing sort by OptionName

                       foreach ($OptionsData['data'] as $key => $value)
{

                               $returnedOptions[$value['OptionName'][0]]
= $value['UniqueID'][0]." - ".$value['OptionCost'][0];

                       }

                       

                       // sort array on key (aka OptionName)

                       ksort($returnedOptions);

                       

                       // Add sorted options to event list

                       foreach ($returnedOptions as $key => $val) {

                               $uniqueID = substr($val,0,strpos($val," -
"));

                               $optionCost =
number_format(substr($val,strpos($val," - ") + 3),2);

                               $events_list .= "<input type=\"checkbox\"
name=\"Choice_".$uniqueID."\" value=\"".$uniqueID."\">&nbsp;".$key;

                               

                               // check to see if $optionCost is zero

                               If($optionCost == 0){

                                      $events_list .= "<br>";   //Don't
show cost if zero, just add line break

                               } else {

                                      $events_list .= " -
$".$optionCost."<br>";  //Show cost 

                               }

                       }

               }

        }

}

?>

 

 

Salvador

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://localhost/pipermail/fx.php_list/attachments/20080802/ed87fb47/attachment.html


More information about the FX.php_List mailing list