Reply to Re: How can I get all enum values of field SMTH?

Your name:

Reply:


Posted by totalstranger on 05/10/06 15:03

On or about 5/2/2006 8:55 AM, it came to pass that
talthen.z-serwera.o2@nospam.pl wrote:
> Hello,
> How can I get all enum values of field SMTH? Do I have to use "SHOW CREATE
> TABLE" and parse the results? Is there a easier way?
>
> Regards,
> Talthen

This code builds either a HTML dropdown or check box from an enum or
set. May not be what you want but should give you an idea of what to do.

<?php
function
DrawFromDB($table,$field,$type,$data="",$sort="yes",$title="",$mult="")
{
//connect to DB;
$query=mysql_query("SHOW COLUMNS FROM ".$table." LIKE
'".$field."'") or die (mysql_error());
if(mysql_num_rows($query)>0)
{
$row=mysql_fetch_row($query);

$options=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row[1]));
if ($sort =="yes")
sort ($options);
$ARay = explode(",",$data);
}
switch ($type)
{
case "select":
$text="\n\n<select name='". $field . $mult. "'>\n";
if ($title > "")
$text.="<option value=\"\">" . $title . "</option>\n";
for ($i=0;$i<count($options);$i++)
{
$selected = NULL;
if ($data == $options[$i])
$selected ="SELECTED ";
$text.="<option " . $selected .
"value=\"".$options[$i]."\">".ucfirst($options[$i])."</option>\n";
}
$text.="</select>\n\n";
break;

default:
$text="\n";
for ($i=0;$i<count($options);$i++)
{
$checked=NULL;
for ($j=0;$j<count($ARay);$j++)
{
if ($ARay[$j] == $options[$i])
$checked=" CHECKED ";
}
$text.="<INPUT TYPE='checkbox'" . $checked . " NAME='" . $field."[]'
VALUE='". $options[$i] . "'>".ucfirst($options[$i])." \n";
}
$text.="\n";
break;
}
return $text;
}
?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация