Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get field length

Status
Not open for further replies.

MasterKaos

Programmer
Jan 17, 2004
107
GB
I have a lot of varchar fields of various lengths in my database. I want to implelemnt some simple HTML validation for my PHP pages, using the "maxlength" attribute of input statemaents to limit the max length to the length of the fields.

Are there any MySQL or PHP funcitons that will give me the length for a given field? I've looked around and so far i think the only way to do this would be to use the desc statement in MySQL and then use substring functions in PHP to get rid of the varchar() bit and be left with just the number. Was wonderring if there is a better way. Oh my database type is innoDB or whatever the default is. I'm running MySQL 4.0.20-standard and PHP 4.3.7

Thanks!

----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
MySQL violates Codd by not storing its data dictionary in the schema, so parsing desc is the only way.
 
Heres a way... not the best though, but it works
Change the top info

<?php
$dbdata="Some_Database";
$dbuser="root";
$dbpass="";
$mydump="/usr/bin/mysqldump";

$cmd = $mydump." -u".$dbuser." ";
$cmd = $cmd." -p".$dbpass." ";
$cmd = $cmd.$dbdata." -d";
$output = `$cmd`;
$o = explode("\n", $output);
for ($i=0; $i < count($o); $i++) {
if (ereg("varchar", $o[$i])) {
echo $o[$i]."<br>\n";
}
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top