RSS

PHP ORM – Create select box with mysql set or enum

05 Sep

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 svnlabs_set (
name SET(‘lamp’,’web’,’linux’,’joomla’)
);

CREATE TABLE svnlabs_enum (
name ENUM(‘lamp’,’web’,’linux’,’joomla’)
);

If we want to fill the html select box with these two tables…

SHOW COLUMNS FROM svnlabs_set;
> set(‘lamp’,’web’,’linux’,’joomla’)

SHOW COLUMNS FROM svnlabs_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….

Advertisements
 
3 Comments

Posted by on September 5, 2010 in CakePHP, MySQL, Open Source, php, Tips, Web Application

 

Tags: , , , , , , ,

3 responses to “PHP ORM – Create select box with mysql set or enum

  1. admin

    September 11, 2010 at 3:43 am

    hello, very good…

     
  2. admin

    September 11, 2010 at 3:43 am

    very good

     
  3. blog.svnlabs.com

    October 13, 2010 at 3:50 am

    Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also…. Greetings from the Speedy DNS

     

Leave a Reply

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

 
%d bloggers like this: