abcd abcd - 25 days ago 18
PHP Question

Php pdo display enum values in dropdown

i am trying below code to display list of enum values in select dropdown box.
but its displaying only dropdown box, but values are not displaying....

tablename = tbl_users, column name = userStatus

<select>
<?
$stmt = $user_home->runQuery('SHOW COLUMNS FROM '.tbl_users.' WHERE field="'.userStatus.'"');
while($data = $stmt->fetch()) {
foreach(explode("','",substr($row[1],6,-2)) as $option) {
print("<option>$option</option>");
}
}
?>
<select>


enter image description here

Note : I really tried lot before posting question here & i am new to php coding, still learning....

Answer

For display enum value as dropdown you can do something like this.

<?php $status = array('Y'=>'Approve','N'=>'unapprove');  ?>
<select>
<?php foreach($status as $key=>$state) { ?>
<option value="<?php echo $key;?>"><?php echo $state;?></option>
<?php } ?>
</select>
Comments