OZONE Asylum
Forums
Server-Side Scripting - Oh my!
mysql_fetch_fields as field_name => max_length array();
This page's ID:
31073
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hey thanks again for the starting point you gave me. I am happy to say i came up with a solution. If anyone is wondering what i came up with here it is: once again my table structure is: [code] DROP TABLE IF EXISTS `table`; CREATE TABLE `table` ( `id` int(11) unsigned NOT NULL auto_increment, `sUsername` varchar(35) NOT NULL default '', `sPassword` varchar(40) NOT NULL default '', `sFName` varchar(35) NOT NULL default '', `sMName` varchar(35) default NULL, `sLName` varchar(35) NOT NULL default '', `sAddr1` varchar(40) NOT NULL default '', `sAddr2` varchar(35) default NULL, `sCity` varchar(35) NOT NULL default '', `sState` varchar(35) NOT NULL default '', `sPCode` varchar(35) NOT NULL default '', `cCountryCode` char(2) NOT NULL default '', `sPhone` varchar(30) NOT NULL default '', `sEmail` varchar(80) NOT NULL default '', `sQuestion` varchar(255) default NULL, `sAnswer` varchar(255) NOT NULL default '', `dtInserted` timestamp NOT NULL, `dtUpdated` datetime default NULL, `iAccessLevel` tinyint(4) NOT NULL default '1', `is_banned` tinyint(4) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB; [/code] This is the code I came up with... [code] $sql = "DESCRIBE table"; $fields = mysql_query($sql); $arrFields = array(); while ( $arrRow = mysql_fetch_object($fields) ) { # fields with lengths will have the '(' # get the position of the number after the '(' $pos = strpos($arrRow->Type,'(') + 1; # get the position of the number before the ')' $pos2 = strpos($arrRow->Type,')'); #get the number if digits for the length $length = $pos2 - $pos; # set maxlength to the number inside the '()' $iMaxsize = substr($arrRow->Type, $pos, $length); # if the field has a mex length then place the field $key and $value into the array; $arrFields[$arrRow->Field] = $iMaxsize; # if there is no '(' then the field does not have a max length if (strpos($arrRow->Type,'(') == '') { # unset the array value if it doesnt have a max length unset($arrFields[$arrRow->Field]); } } print_r($arrFields); [/code] which results in this: Array ( [id] => 11 [sUsername] => 35 [sPassword] => 40 [sFName] => 35 [sMName] => 35 [sLName] => 35 [sAddr1] => 40 [sAddr2] => 35 [sCity] => 35 [sState] => 35 [sPCode] => 35 [cCountryCode] => 2 [sPhone] => 30 [sEmail] => 80 [sQuestion] => 255 [sAnswer] => 255 [iAccessLevel] => 4 [is_banned] => 4 ) [small](Edited by [url=http://www.ozoneasylum.com/user/3672]Hustluz[/url] on 06-28-2009 01:40)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail