Querying a Drupal database table?
terryit3 - January 22, 2008 - 18:56
I am trying to figure out how to query a specific table (tbl_edeath) in my Drupal database.
I have the fields, LNAME, FNAME, OTHER, DATE and RECNO (record number).
I would like my site visitors to be able to search by first or last name and retrieve results from this table.
How is this possible in Drupal? Where do I write the query to pull the data?
I have tried the AjaxTable module, but it's not very user friendly and I've not had much luck with it. I'd prefer to just write an SQL statement and pull the data that way.
Thanks,
T

I've been reading through
I've been reading through the forums and documentation, but can't seem to figure out how to do this.
If anyone can offer some help, I'd appreciate it!
I need to create a search form to query the "tbl_edeath) in my Drupal database. Using the site-search returns no results (obviously :) )
Terry
I found a site that does what I need.. now to figure it out.. http://www.louisvillelibrary.org/obit
I am curios, how are you
I am curios, how are you inserting the data into the table that it doesn't pass through the search index?
After Drupal was installed,
After Drupal was installed, I imported the tables via PHPMyAdmin from an SQL dump of another databases tables.
I was told Drupal cannot search any tables it does not own, but I am not sure what to do next.
This is true. Have a look at
This is true. Have a look at the Search module that is part of Drupal's Core. How it works is, when you enable this module the search.install file creates 3 tables in your Mysql data base: search_dataset, search_index, search_total. The search_dataset indexes every node as whole text into a data for phrase searches and assigns each a sid# (search id#), type, and a reindex#. Search_index indexes every word on the site into a word column and assigns each a sid#, type, and a score. And the search_total indexes every word into a word column and assigns it a number based on how often the word appears on the site over how many words are on the site into a count. What the search.module file does: this does all the hard work: first it sets up the Admin interface for querying the database to index the site, second in this script is the coding for the module to populate the database tables that the search.install created. It does this by telling database to populate the tables based on anything that is in a node. ie: if it is associated with a nid (node id #), then use it to populate the tables. This is done at every cron, the search.module will go through the site and reindex it. Lastly what the search.module does is creates the User Interface which does 2 things, first it makes the search form (the little text field and search button) and then it queries the database based on the keywords or phrases that were entered. It doesn't just query the DB tho, it runs through a bunch of operation based on the associated scores and counts to result in an intelligent, relevance based return.
What this means for you is that it won't be very easy to query your database using the built-in search method, but if you are willing to use a little elbow grease and do some .module dissection you could come up with a very powerful sollution. The .module text is long, but it is fairly well noted and it will become apparent rather quickly what the module is doing.
Solution 1 You create a content type and insert your data manually. This option will allow you to have the search.module index your info on your next cron cycle and allow yo to have a nice interface to upload additional data without having to go into phpMyAdmin. With this solution you could create new roles, assign them to select users, and allow only those users to use the search module in the Access Control section of the site. You could go even further and have select few be able to use the Advanced Search Options. This would be the cleanest way to do things.
Solution 2 You create a new custom search.module. So you know what your database looks like, in this solution you copy the search module folder, rename it, and then go in and change the text in the modules to call your tables and index columns. With this solution as well, when you enable the module you could have the NEWsearch.install create the proper tables and index columns for you in the Database. The only real positive about this solution is that you can have multiple instances of the search module (each uniquely named of course) querying different table-sets and each would have its own Admin section. If done properly, you could add new search modules by copying and renaming the module (slightly more complicated than it sounds) and creating a new type for the module to index and search (also a bit more complicated than it sounds), and the new module would create the tables for you, give you a new Admin interface, and User interface, and query only the information of that new type. But, for the sake of simplicity I'd go with Solution 1.