Changeset 777 for trunk/include


Ignore:
Timestamp:
Apr 30, 2005, 4:36:57 PM (19 years ago)
Author:
plg
Message:
  • user list updated : ability to filter list on status. Function get_enums comes back to retrieve the list of possible status in the database.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r764 r777  
    3535//----------------------------------------------------------- generic functions
    3636
     37/**
     38 * returns an array containing the possible values of an enum field
     39 *
     40 * @param string tablename
     41 * @param string fieldname
     42 */
     43function get_enums($table, $field)
     44{
     45  // retrieving the properties of the table. Each line represents a field :
     46  // columns are 'Field', 'Type'
     47  $result = pwg_query('desc '.$table);
     48  while ($row = mysql_fetch_array($result))
     49  {
     50    // we are only interested in the the field given in parameter for the
     51    // function
     52    if ($row['Field'] == $field)
     53    {
     54      // retrieving possible values of the enum field
     55      // enum('blue','green','black')
     56      $options = explode(',', substr($row['Type'], 5, -1));
     57      foreach ($options as $i => $option)
     58      {
     59        $options[$i] = str_replace("'", '',$option);
     60      }
     61    }
     62  }
     63  mysql_free_result($result);
     64  return $options;
     65}
     66
    3767// get_boolean transforms a string to a boolean value. If the string is
    3868// "false" (case insensitive), then the boolean value false is returned. In
Note: See TracChangeset for help on using the changeset viewer.