Archive for the ‘combo’ tag
The easiest page dropdown list on CodeIgniter
Imagine you want to create a dropdown (or combo) to display numbers from a range of values, or page numbers from 1 to the total of pages.
With CodeIgniter and PHP, that is extremely easy. Here is an idea that may help you in some situations.
<?php echo form_dropdown('number', range(0,10) ); ?>
The line of code creates a <SELECT> control with the name number, and passing an array of values from 0 to 10. form_dropdown() is part of the CodeIgniter’s form helper, while range() is a PHP function that retrieves an array with a range of values.
Take in mind that form_dropdown can receive an assoc array of keys and values while in this example we are only passing an array of values. When passing an array of values, then the options will be numbered from 0 to N, so if you need options starting from 1 instead of zero, take in mind that probably you need to modify that line of code (using array_combine() may be useful).



