solution/alternative for dropdown menu with 100+ entries wanted - php

I have a html form that have one field that need to be filled with a value that match a selection from my database.
This is a typical form where you fill in contact information for a person, and then you assign a value based on a selection from the database. This selection will contain results between 10 an 200 hits..
A dropdown menu would fit to the layout and user interaction, but having 150 entries in a dropdown does not feel like a good solution.
Any suggestion for how to handle this in a nice and simple way? Simple is the keyword.
PHP and MySQL is used.
Any help is appreciated.

150 values in a select field is ok no problem, I have seen more and working good.
You can use a code like this to make it nicer and more accessible:
<select name="names" size="5" id="names">
<option>val1</option>
<option>val2</option>
<option>val3</option>
<option>val4</option>
...
<option>val150</option>
</select>

Select2 was a great solution.
Thanks to Mark Baker and Doink for pointing out that direction in the commments.
Having several values is not a problem itself, it is however not useable for the end user when it became hundreds of values.
Select2 offer a nice solution and filter out unwanted result in a handy way.
Easy to implement as well.

Related

Yii Cgridview Dynamic Columns

I am looking at customising the yii cgridview. I want to be able to allow users to select which columns they wish to see. Currently I am selecting the exact columns which will be displayed.
I have had a look for information on this but do not seem to be getting very far, maybe I am not looking for the correct terms or their is a specific term for this. Ideally users can click a button and tick the boxes which will be seen. I have seen this implemented on x2crm
http://demo.x2engine.com/index.php/accounts/index
I also like the ability to move the columns around ie resort the order of the columns and the ability to resize the columns when more are added. I realise someone isn't going to come along and do this for me, but certainly if someone could provide me any information or similar requests, it would be greatly appreciated.
After a long gruelling search I have found something that may in fact be the solution to both of my requests. An extension for Yii exists that allow for you to chooser the columns you wish to display with a simple tick box selection, as well as allowing for reordering of columns.
http://ecolumns.demopage.ru/index.php
The link above takes you to the demo page for the extension and the link below is the link to the extension download page.
http://www.yiiframework.com/extension/ecolumns/
This is by far the easiest way to implement this functionality on your web app.
Start by reading the docs for CGridView,
The constructor for it takes in an array specifying which columns to display (and whether to allow sort on them, etc) so allowing users to select which columns they want to see is almost trivial:
Display a form with checkboxes, the values of which are the names of the columns. When the user submits the form, loop over the checkboxes and add each of the present fields to the array that is passed to CGridView.
It is a little more complicated if you want to have specific settings for the column (i.e. a specific column header, or formatting) however not too much - in that case you just define an array holding the settings for it, and add that array to the total array you submit to CGridView.
Allowing drag and drop of the columns is a far more challenging enterprise, and may not actually be possible without a custom implementation - this is because CGridView is inherently just a table i.e. you could drag and drop rows easily (as they are whole items), but dragging a dropping a row is in reality dragging and dropping a lot of separate cells. However, there are jQuery examples that could get you started - and it wouldnt be a huge issue to implement a CGridView that uses divs instead of a table, and uses cells inside columns, rather than cells inside rows.
I hope that helps a little.

Cascading Dropdown In PHP

I have two dropdown list in my page i.e Location and Employee.
What I want to do is that I want to filter the employee according to the location.
That is ,,, When I select location Delhi than all the employees at delhi location are came into employee dropdown.
Is it possible in PHP????
Please help me out
That is not possible using just PHP unless you are okay with a page refresh in between. There are many ways to do this in JavaScript, have you tried using JavaScript?
EDIT: There might be some complex way using CSS3 selectors, but even if there is I would not advise doing it.
yes nothing is imposible. you can do it.. but you have to use scripting languages like ajax to accomplish that.. If you need more help please post your code....Yuo could find the answer here..
Populating second drop down based on selection of first with value from first database
Yes it's possible using php with ajax implementation.
Here's a good tutorial in which country, state, city example given. Hope this will help you.
http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html

jQuery and PHP suggested answers

Hey guys, there is a form where the user select some of his friends and I'm curious on how I can implement a list that searches simultaneously while the user is typing a friend's name and when he selects the name the name is written in the text box(jQuery). And if the user wants to select more than one friend, when I'm inserting the names in the database, how can I separate the names that are written in one input field?
You should take a look at the jquery auto-complete plugin:
http://docs.jquery.com/Plugins/autocomplete
Also, you could separate the names using commas.
Are you looking to write your own plugin or would you like to use an existing one?
If you want something ready made, here are a few examples
if you want something extremely light, only 6kb packed, this one would be the best choice
Autosuggest jQuery Plugin
Older one but still good
Tokenizing Autocomplete
This what already asked here on this site.
Facebook style JQuery autocomplete plugin
The accepted answer cited this jQuery code.
https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin
http://jqueryui.com/demos/autocomplete/
Although think twice about including the whole jquery ui library for this one plugin
I've implemented this a couple of times, it is not that difficult to achieve decent results and the basic idea that I used was...
1) create an input box.
2) create a div positioned directly underneath the input box.
3) create a jquery keypress handler. if there are more than x characters typed, ajax request.
4) loop through the results, and if they exist, append result divs to the result box.
5) show the result box.
I can dig up some example code if you would like. Not sure what you are talking about with the select multiple, but you could keep a variable of selected, and change the color of the result div when it is clicked on, this way many results can be selected and then processed later.

jqgrid - filter results with multiple selects like excel

i would like to use multiple filter options for all columns with using select form object.
When a columns filter selected, other select object options may filled to this selection.
Clearly, i want to filter jqrid columns as same excel filter feature.
I use php for server side.
Thank your very much for your help and suggestions already now.
What you want to implement should be combination of the usage of Toolbar Searching (see this demo as an example and the usage of 'change' custom event handle as dataEvents inside of the searchoptions. Inside of your 'change' handle you can make an ajax request to the server and then rebuild <select> element of the second drop-down list.
You can find more examples used the same technique with editoptions. Both work based on the same idea. The technique is not simple, but it works. I recommend you to read this thread.

how can i make a dynamic drop down box in php?

i need in an php file three drop down boxes or multiple select boxes.
the entries from these boxes are in a mysql database.
the single problem is that the entries in the thrid box depend on the second, and the entries in the second depend on the first.
can someone help? know any examples?
There are basically 3 ways to achieve this:
Use JavaScript to submit() the form to the server side during onchange of the dropdown and let PHP load the options and render the child dropdown accordingly based on the selected dropdown value. Technically the simplest way, but also the least user friendly way. You probably also want to revive all other input values of the form.
Let PHP populate all possible child dropdown values in a JavaScript array and use a JavaScript function to fill and display the child dropdown. A little bit trickier, certainly if you don't know JavaScript yet, but this is more user friendly. Only caveat is that this is bandwidth and memory inefficient when you have relatively a lot of dropdown items. Imagine three dropdowns which can each hold 100 items, that would mean a JS array of 100 * 100 * 100 = 1 million items. The page might then grow over 1MB in size.
Let JavaScript fire an asynchronous (ajaxical) HTTP request to the server side and fill and display the child dropdown accordingly. Combines the best of options 1 and 2. Efficient and user friendly. jQuery is extremely helpful in this since it removes the concerns about crossbrowser compatibility with regard to firing ajaxical requests and traversing the HTML DOM tree. You would otherwise end up with double, triple or even much more of code needed to achieve this.
If you let know in a comment or an update of your question which way you would prefer and where exactly you're stucking while implementing the solution, then I'll maybe update the answer to include a basic kickoff example.
I'm from Portugal, so, what we do it's based on Portuguese language, never the less, we've made many working websites and platform's with what you want, please check this link...
if this is what you want, I can send you the code:
http://www.medipedia.pt/home/home.php?module=farmacia

Categories