SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: default colum values
-
Aug 24, 2001, 10:10 #1
- Join Date
- Apr 2001
- Location
- Des Moines, IA
- Posts
- 346
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
default colum values
Is there a way to get the default column values from a table in an array like $row[col_name]?
-
Aug 24, 2001, 10:29 #2
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Like whatever the column is using as default. For instance you create a table like with a field like
user varchar(50) DEFAULT 'freddy' NOT NULL
You want to grab the default values for the table and stick them in an array?Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Aug 24, 2001, 11:01 #3
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey I am not sure if this is what you want, but it will grab all the data it can about the fields in a table and stick them in an array.
PHP Code:<?
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
$dbname = '';
$tablename = '';
$db = mysql_connect($dbhost, $dbuser, $dbpass) or DIE(mysql_error());
mysql_select_db($dbname);
$result = mysql_list_fields($dbname, $tablename);
$num = mysql_num_fields($result);
for($i=0;$i<$num;$i++) {
$fields[] = array("name" => mysql_field_name($result, $i),
"flags" => mysql_field_flags($result, $i),
"length" => mysql_field_len($result, $i),
"type" => mysql_field_type($result, $i)
);
}
?>
<table>
<tr>
<td><strong>Field Name</strong></td>
<td><strong>Field Flags</strong></td>
<td><strong>Field Length</strong></td>
<td><strong>Field Type</strong></td>
</tr>
<?
foreach($fields as $key => $val) {
?>
<tr>
<td><?=$fields[$key]['name']?></td>
<td><?=$fields[$key]['flags']?></td>
<td><?=$fields[$key]['length']?></td>
<td><?=$fields[$key]['type']?></td>
</tr>
<?
}
?>Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks