[PHP] Build Categories based on an static Array

2009-11-09 Thread Don Wieland
I am trying to build a SELECT MENU (with categories). I cant seem to  
get the syntax correct. Little help:


// Get Areas values for MENU
$AreasList = select name=\Area_id\option value=''/option;

$queryR = array(0 = 'Domestic','International','Special');
while($rowR = $queryR-fetch_assoc()) {

$AreasList .= optgroup label=\{$rowR['Region_Name']}\;
$Area_Type = $rowR['Area_Type'];


	$query2 = SELECT Area_id,Area FROM Areas WHERE  
`Area_Type`='$Area_Type' ORDER BY Area;

$results2 = $db-query($query2) or die(No Area found.);

while($row2 = $results2-fetch_assoc()) {
		$AreasList .= option  
value='{$row2['Area_id']}'{$row2['Area']}/option;

}
$AreasList .= /optgroup;
}

$AreasList .= /select;



Don Wieland
D W   D a t a   C o n c e p t s
~
d...@dwdataconcepts.com
Direct Line - (949) 305-2771

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our  
Developer Support Plan at:

http://www.dwdataconcepts.com/DevSup.html

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro  
9 or higher

http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Build Categories based on an static Array

2009-11-09 Thread Daevid Vincent
($MatchToThis, $key)
|| $key == $MatchToThis) $out .=  selected;
//if ($size  1) $out .= 
title=\.stripslashes($val).\;
if ($size  1) $out .= '
onmouseover=this.title = this.text;';
$out .= '';
$out .= stripslashes( $val ? $val : $key );
$out .= /option\n;
}
} //foreach
} //if count(listArray)

$out .= /select\n;

if ($echo)
{
echo $out;
return count($listArray);
}
else return $out;
}

/**
* @return   mixed 'selected' or false
* @paramarray $haystack the array that contains the selected items
* @paramstring $needle the item in the $haystack we're looking for.
* @author   Daevid Vincent [dae...@]
*/
function selected_if_in_array($haystack, $needle)
{
if ( !is_array($haystack) ) return false;
return ( in_array($needle, $haystack) ) ? 'selected' : false;
}

/**
* Take an array of unique values and make the keys the same as the value.
* Useful for select boxes for example.
*
* @access   public
* @return   mixed
* @paramarray $myArray
* @author   Daevid Vincent [dae...@]
*/
function double_up_uh_uh($myArray)
{
foreach($myArray as $k = $v)
$tmp[$v] = $v;
return $tmp;
}

/**
* Returns the first non-empty value in the array,
* Works much like mySQL's function,
* except this is an array passed in rather than a list of parameters.
*
* @access   public
* @return   mixed
* @paramarray $myArray
* @author   Daevid Vincent [dae...@]
*/
function coalesce($myArray)
{
foreach($myArray as $a) if ($a) return $a;
} 

 -Original Message-
 From: Don Wieland [mailto:d...@dwdataconcepts.com] 
 Sent: Monday, November 09, 2009 2:59 PM
 To: php-general@lists.php.net
 Subject: [PHP] Build Categories based on an static Array
 
 I am trying to build a SELECT MENU (with categories). I cant seem to  
 get the syntax correct. Little help:
 
   // Get Areas values for MENU
   $AreasList = select name=\Area_id\option 
 value=''/option;
   
   $queryR = array(0 = 'Domestic','International','Special');
   while($rowR = $queryR-fetch_assoc()) {
   
   $AreasList .= optgroup label=\{$rowR['Region_Name']}\;
   $Area_Type = $rowR['Area_Type'];
   
 
   $query2 = SELECT Area_id,Area FROM Areas WHERE  
 `Area_Type`='$Area_Type' ORDER BY Area;
   $results2 = $db-query($query2) or die(No Area found.);
   
   while($row2 = $results2-fetch_assoc()) {
   $AreasList .= option  
 value='{$row2['Area_id']}'{$row2['Area']}/option;
   }
   $AreasList .= /optgroup;
   }
 
   $AreasList .= /select;
 
 
 
 Don Wieland
 D W   D a t a   C o n c e p t s
 ~
 d...@dwdataconcepts.com
 Direct Line - (949) 305-2771
 
 Integrated data solutions to fit your business needs.
 
 Need assistance in dialing in your FileMaker solution? Check out our  
 Developer Support Plan at:
 http://www.dwdataconcepts.com/DevSup.html
 
 Appointment 1.0v9 - Powerful Appointment Scheduling for 
 FileMaker Pro  
 9 or higher
 http://www.appointment10.com
 
 For a quick overview -
 http://www.appointment10.com/Appt10_Promo/Overview.html
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php