|
wordpress or php code to populate a dropdown or select options from a database
<?php
$posts_rows = $wpdb->get_results( "SELECT ID,post_title,post_name,guid FROM wordpress_posts WHERE post_type='attachment'" );
?>
<!-- Start Image Drop Down-->
<select style="width:250px;" id="<?php echo trim($background->id); ?>" onchange="update('<?php echo trim($background->id); ?>')" name="selectedimage">
<?php
if ($posts_rows) :
foreach ($posts_rows as $post) :
?>
<option value="<?php echo trim($post->guid); ?>" ><?php echo trim($post->post_name);; ?>
</option>
<?php
endforeach;
else :
?>
<option value="">Not Found</option>
<?php
endif;
?>
</select>
<!-- End Image Drop Down-->
|