I created a drupal custom module for my website, the module functionality is it display list of students who have registered in my site. Now I want to update my custom module with search functionality, the search function should like google search function.

My custom module look like following structure

Current Module Look like

Now I want to implement the search function in my custom module. When I search using the fields of the table like student name, gender, author name, and status, how do I do this?

Expecting result

  • 2
    Write more details about the setup - how do you define students: as entities, user profiles, node types or you do manually everything? You could use Views to build the tables on screenshots and it will provide you with filters for searching as well. – Aram Boyajyan Oct 1 '13 at 7:09
  • I do manually everything. can you please explain how to make this in views. – vinox Oct 1 '13 at 7:14
  • 1
    In that case check out hook_views_data() as it will allow you to display content in custom tables through views. However, I'd strongly recommend to use views if possible - it will give you caching, paging, filters and much much more out of the box. You may need to reorganize your setup, but it will be worth of it in the long run. – Aram Boyajyan Oct 1 '13 at 7:17
  • See this question for more information. – Aram Boyajyan Oct 1 '13 at 7:20
  • 1
    Just curious - how come you are new to Views yet built a module that has database queries, schema definition and other complex stuff ? – AyeshK Oct 1 '13 at 13:50

You have few options:

  1. Use hook_views_data() to hook your custom tables with Views.

  2. Use Data module as it features automatic integration with Views.

  3. Reorder your setup to use Drupal's node type/user profile/entity, which has Views support out of the box.

Doing it really manually will be a waste of time, unless you need some very specific functionality that can be hardly achieved by using Views for it.

Views will also provide you with caching, paging and it will be easier to maintain it in the future.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.