create radio button selection from data set

function user_type_generate_eligibles($user_name_in) {
  // This function returns an array of arrays. The top level
  // array will be indexed 0 through n-1. Each element of
  // the top level array will contain an array having two
  // indices: id and label which specify a user_type.
  // The top level array is a collection of user types which
  // the user CAN CREATE using the createANewUser.php script.
  // The user types which the user CAN CREATE satisfy two
  // criteria: 1. The user is eligible to have them
  // 2. The user does NOT have them yet.
  // This function returns FALSE if no user types can be
  // returned. It will abort if something goes wrong.
  
  // Initialize index used in array of all user types.
  $id = 1;
  
  // Get all user types from database. Place them in
  // $userType_inSystem[]. If this array is empty then
  // $id will still be 1 after the loop. Otherwise, $id
  // will have value one more than the highest index of
  // the array.
  $query = "SELECT id, label
            FROM available_user_types";
  $result = mysql_query($query);
  while ($row = mysql_fetch_array($result)) {
    $userType_inSystem[$id] = $row;
    $id += 1;
  }
function user_type_make_radio_button($user_type_field_options_in) {
// Returns a string containing the radio button form field
// using the given array of user types. If function fails
// kill the script. The input array is of the type generated by
// the function user_type_generate_eligibles($user_name_in).

  // If $user_type_field_options_in is not set or is not an array or it is an
  // array which has no elements then abort.
  if (!IsSet($user_type_field_options_in) || !is_array($user_type_field_options_in)
    || sizeof($user_type_field_options_in) < 1) {
    die("Function user_type_make_radio_button failed because it was not passed ".
    "an array.\n - Programmer.");
  }
  
  // Loop which generates the radio button.
  $user_type_button = "";
  reset($user_type_field_options_in);
  while ($array_cell = each($user_type_field_options_in))
  {
    $temp_1 = $array_cell['value']['id'];
    $temp_2 = $array_cell['value']['label'];
    $user_type_button .=
    "    <input type=\"radio\" name=\"user_type\" id=\"$temp_1\" value=\"$temp_1\" />" .
    "    <label for=\"$temp_1\">$temp_2</label>" .
    "<br/>\n";
  }
  
  // Return the radio button string.
  return $user_type_button;
}
Advertisements

About samehramzylabib

See About on https://samehramzylabib.wordpress.com
This entry was posted in Coding, PHP Form Fields and tagged , , , . Bookmark the permalink.

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s