DB Forms in DRUPAL

Hi,

I found this part of code is very useful for adding custom forms in Drupal.

 

<?php
function booksearch_form() {
   
$output .= drupal_get_form('booksearch_my_form');
   
$output .= booksearch_query();
    return
$output;
}

function booksearch_query() {

    $sql = "SELECT * FROM bookshelf"; //your uber cool query goes here
   
   
db_set_active('booksearch'); //my separate db connection specified in modified settings.php
   
$result = pager_query($sql,10);
   
db_set_active('default'); //my default drupal db connection specified in modified settings.php
   
   
$output = '<table>'; //I know, tables bad, theming inside a data function bad..
   
   
while ($row = db_fetch_array($result)) {
       
$output .= '<tr><td>'.$row[isbn];
       
$output .= '</td><td>'.$row[author];
       
$output .= '</td><td>'.$row[title];
       
$output .= '</td><td>'.$row[genre];
       
$output .= '</td></tr>';
    }
   
$output .= '</table>';
    return
$output;   
}
?>

More..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.