Determining Database Field Lengths
Here's the scenario: You've set up your database and now you're building your web page to display the information. You have a text field that stores a city name. In the database you've specified the maximum length to 50 characters. In HTML, you add on your
maxlength attribute and specify it as 50. An easier way would be to have it automatically "know" what the length was.
In ASP, you can do this using the
DefinedSize property of the field. For example,
<input type="text" name="myfield" value="<%=rs("fieldname")%>" maxlength="<%=rs("fieldname").DefinedSize%>" >
You can do the same thing in PHP but it's a little more complicated. Here's an example:
$length = mysql_field_len($rs, 0); The problem here is that you can only pull out one field length at a time and only using an index. The index being the order that the field names are specified in the
SELECT. Therefore, it might be easier to loop through and copy all the field names and their lengths into an associative array.