$field->max_length not working correctly? |
[eluser]djstu2010[/eluser]
Hi. I am trying to write some code to determine the maximum length of a field. I am using $field->max_length as instructed by http://ellislab.com/codeigniter/user-gui...ields.html However, this seems to be reporting the length of the field value, i.e. the number of characters in the field value, rather than the maximum length of the field, as suggested by the manual. I am using MySQL. Does the feature work correctly? The context of the code is that I am trying to write a helper function to display a generic data form, based on the control type of each field in a given table or query result.
[eluser]LuckyFella73[/eluser]
This function relies on the php function Code: mysql_fetch_field() which returns the value of the longest entry in that column and not the defined max value defined when setting up the table. So the feature is working correct - maybe the user guide could be a bit more detailed in this point.
[eluser]djstu2010[/eluser]
OK. Can anyone suggest how to modify the CodeIgniter code to produce the desired result? Or another way of doing it (my function is in a helper file and based on a query result, not a table name, as it may be combining data from multiple tables).
[eluser]djstu2010[/eluser]
Managed to fix it myself, by making these modifications in mysql_result.php Code: function field_data()
[eluser]Julia Yan[/eluser]
Thanks djstu2010, I got *_^ I add one line into file at system\database\drivers\mysql\mysql_result.php line 95 $F->len = mysql_field_len($this->result_id, $index++); But Message: Undefined variable: index Filename: mysql/mysql_result.php Line Number: 95 -------------------------new question, how to get single value from field_data($table); exam, get length of field = 'name' without foreach $fields = $this->db->field_data($table); echo $field->len['name'];//does not work?
[eluser]Unknown[/eluser]
Maybe so: $query = $this->db->query("SELECT `name` FROM $table"); $field = field_data($query); |
Welcome Guest, Not a member yet? Register Sign In |