Someone gave me the idea, and I coded it tonight
use for making option lists of legal values from a mysql field that is
enum'd.
You don't have to know the values ahead of time.
<function>----------------------------------------------------------------------
function mysql_fetch_enums( $link,  $table_name, $field_name ){
  $mysql_datatype_field = 1;
  if (!$result = mysql_query ("SHOW COLUMNS FROM $table_name LIKE
'$field_name'", $link ) ){
    $output=0;
  } else {
    $mysql_column_data = mysql_fetch_row( $result );
    if ( !$enum_data= $mysql_column_data[$mysql_datatype_field] ){
      $output=0;
    } else if ( !$buffer_array=explode("'", $enum_data) ){
      $output = 0;
    } else {
      $i = 0;
      reset ($buffer_array);
      while (list(, $value) = each ($buffer_array)) {
        if( $i % 2 ) $output[] = $value;
        ++$i;
      }
    }
  }
  return $output;
}
</function>----------------------------------------------------------------------

<test>----------------------------------------------------------------------
<?php
$link = mysql_connect ( 'SERVER', 'USER', 'PASSWORD' )
      or die ("Could not connect");
mysql_select_db('DATABASE', $link)
      or die ("Could not select database");
$holder = mysql_fetch_enums ( $link, 'TABLE_NAME', 'FIELD_NAME' );
  $i=0;
  reset ($holder);
  while (list(, $value) = each ($holder)) {
    echo "UseForOption$i: $value<br>\n";
    ++$i;
  }
  mysql_close();
?>
</test>
----------------------------------------------------------------------
-- 
________________________________________________________________
Sites by friends of mine: http://www.myhiddentreasures.com/
________________________________________________________________
WARNING personal propaganda signature
TAKE WHAT YOU LIKE AND LEAVE THE REST

SINCE OUR GOVERNMENT WON'T PRESERVE OUR CLIMATE, IT'S UP TO US!
Imagine ** yourself ** and your kids now an endangered species
<1>Inflate automobile tires to near maximum in summer, -2psi in winter
<2>add insulation to house and hot water heater, and refrigerator,
<3>combine trips in cars, make less of them <4>buy cars, sports
vehicles and recreational vehicles with good if not best mileage
<4>put awnings over windows is summer, remove in winter. <5> add
solar hot water heating. <6>Push for energy recycling clothes
dryers <7> walk more, play outside with your kids! <8> let your
grass grow to 3-4 inches, chokes weeds, saves water and energy,
keeps house cooler <9> Put WHITE or REFLECTIVE materials on
roofs to send energy back into space. <10> Vote for burial of
logging slash onsite in logging areas for better watersheds
and less burned vegetation. <11> compost your leaves and grass,
bury in flower beds, lawns, gardens, or give away. <12> VOTE
for energy and CO2 ratings on ALL products and foods. KNOW how
much damage your purchases do to the climate. <13> Give your kids 
less stuff and more of you. <14> recycle everything you can <15>
limit your children to an average 1 per adult between all your 
marriages. (Only REPLACE yourself, not expand the population)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to