/* -----------------------------------------------------------------------------
Echo an option select menu
Input:
label - The label of the form element (string)
name - Uses as both the name and id of the element (string)
list - An assoicative array of unique ids and display titles
Output: None, this function will echo HTML but return null
----------------------------------------------------------------------------- */
function return_option_select($name, $list, $label='', $v='') {
$ouput = '
';
if ($label != '')
$ouput .= '
';
$ouput .= '
';
return $ouput;
}
/* -----------------------------------------------------------------------------
Echos eturn_option_select
----------------------------------------------------------------------------- */
function echo_option_select($name, $list, $label, $v) {
echo return_option_select($name, $list, $label, $v);
}
/* ------------------------------------------------------
Create a page and test the echo_option_select functions
------------------------------------------------------ */
require_once('site_core.php');
require_once('site_db.php');
// Create the HTML head and container
echo_head('Test 4');
echo '
';
// Test the function with the array
echo_option_select('color', $colors,'Pick a Color');
echo '';
// Get the pageid and title of all pages
$result = run_query("SELECT pageid, title FROM pages");
// Transform it into an associative array
$pages = array();
while ($row = $result->fetch_assoc()) {
$pages[ $row['pageid'] ] = $row['title'];
}
// Dumpt the array
echo '
';
var_dump($pages);
echo '
';
// Test the function with the array
echo_option_select('pageid', $pages,'Pick a Page','usa');
echo '