PHP have rich set of functions to solve real time problems in programming and web development.. thanks to Rasmus Lerdorf
eval — Evaluate a string as PHP code
A SET datatype can hold any number of strings from a predefined list of strings. The ENUM datatype restricts to a single member of the set of predefined strings, the SET datatype allows to store any of the values together, from none to all of them.
CREATE TABLE phpsolutions_set (
name SET(’lamp’,’web’,’linux’,’joomla’)
);
CREATE TABLE phpsolutions_enum (
name ENUM(’lamp’,’web’,’linux’,’joomla’)
);
If we want to fill the html select box with these two tables…
SHOW COLUMNS FROM phpsolutions_set;
> set(’lamp’,’web’,’linux’,’joomla’)
SHOW COLUMNS FROM phpsolutions_enum;
> enum(’lamp’,’web’,’linux’,’joomla’)
now based on column type set list of string values from mysql to php array…
<?php
…….
// if column type is set
$arr = “\$set=”.str_replace(”set”, “array(”, $column[‘Type’]));
eval($arr);
// if column type is enum
$arr = “\$set=”.str_replace(”enum”, “array(”, $column[‘Type’]));
eval($arr);
…………..
?>
Use $set PHP array to fill select box….
One Response to PHP ORM – Create select box with mysql set or enum
Leave a Reply
You must be logged in to post a comment.
You made some first rate factors there. I regarded on the internet for the difficulty and located most people will go along with with your website.