Re: ENUM COL to php

From: Date: Sat, 12 Jan 2002 04:38:55 +0000
Subject: Re: ENUM COL to php
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-80264@lists.php.net to get a copy of this message
On Saturday 12 January 2002 11:30, Mehmet Kamil ERISEN wrote: > Hi, > If I have en ENUM column in a mysql table, can I leverage > this through PHP to restrict user entry with a list? > Other option that I have is to create a lookup table, or > use an array. You'll need to adapt this for your own use, but hopefully you'll get the general idea. #=========================================================== # create_list_from_ENUM #----------------------------------------------------------- # Returns array [enum vals] # # Arguments # --------- # # $dbh : a $dbh object defined in class.DBI.inc # $table : the table to get the ENUM values from # $column : the column containing the ENUM values # #=========================================================== function create_list_from_ENUM($dbh, $table, $column) { $sth = $dbh->prepare("SHOW COLUMNS FROM $table LIKE '$column'"); if ($sth) { $sth->execute(); while ($row = $sth->fetchrow_hash()) { ereg("('(.*)')", $row[1], $temp); $array = explode( "','", $temp[2] ); while (list ($key, $val) = each ($array)) { $return[] = "$val"; } } } return $return; } -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* A shortcut is the longest distance between two points. */

« previous php.general (#80264) next »