Z33M@N Posted June 18, 2010 Share Posted June 18, 2010 Hi there, I'm new to drupal. I'm trying to get data to display when I do a db query. The problem is like this, when I return data I get nothing to display and when I echo on the my local xampp server it works but it's just giving a white page with the data I requested. When I do a return or echo on the live server nothing gets returned or echoed. The only thing that works is when I use drupal_set_message(t('<h2><a href="#">'.$title.'</a></h2>')); Here is my module code can somebody help me out? <?php // $Id$ /** * @file * Searching a database for articles. */ /** * Implementation of hook_menu(). */ function searchsae_menu() { $items['searchsae'] = array( 'title' => 'Search - SAE', 'page callback' => 'searchsae_page', 'access arguments' => array('access content'), ); return $items; } /** * Menu callback. * Called when user goes to http://example.com/?q=formexample */ function searchsae_page() { $output = t('Search SAE for articles.'); // Return the HTML generated from the $form data structure. $output .= drupal_get_form('searchsae_nameform'); return $output; } /** * Define a form. */ function searchsae_nameform() { $form['user_search'] = array( '#title' => t('Search'), '#type' => 'textfield', '#description' => t('Enter search terms.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Searh') ); return $form; } /** * Validate the form. */ function searchsae_nameform_validate($form, &$form_state) { if ($form_state['values']['user_search'] == '') { // We notify the form API that this field has failed validation. form_set_error('user_search', t('You need to enter a search term!')); } } /** * Handle form submission. */ function searchsae_nameform_submit($form, &$form_state) { $search = $form_state['values']['user_search']; return search_output($search); } function search_output($search) { $result = db_query("SELECT articletitle FROM xml_import_db.articles_e WHERE articletitle like '%$search%' GROUP BY articletitle LIMIT 10"); // AND articleparagraph like '%$search%' //query 1 if(!empty($search)){ while($row = db_fetch_array($result)) { $title = array(); $xml = $row['articlexml']; $title = $row['articletitle']; $paragraph = $row['articleparagraph']; $replace = "<b>".$search."</b>"; //str_replace(" ", "-" , $title); //drupal_set_message(t("<h2>".$title."</h2>")); //echo t('<p>'.$title.'</p>'); //echo '<p>'.$title.'</p>'; //drupal_set_message(t('<h2><a href="#">'.$title.'</a></h2>')); //drupal_set_message(t("<p>".substr($paragraph, 0,500)."</p>")); //drupal_set_message(t("<p>".$xml."</p>")); echo $title; } //mysql_close($con); } elseif(empty($search)){ drupal_set_message(t('Query is empty!')); } } Quote Link to comment https://forums.phpfreaks.com/topic/205170-drupal-trying-to-echo-data-but-nothing-happens/ Share on other sites More sharing options...
yozyk Posted June 22, 2010 Share Posted June 22, 2010 Probably, your page has redirect. Try exit('Some text'); . Quote Link to comment https://forums.phpfreaks.com/topic/205170-drupal-trying-to-echo-data-but-nothing-happens/#findComment-1075577 Share on other sites More sharing options...
tomcant Posted June 27, 2010 Share Posted June 27, 2010 You should check that your function `search_output()' is ever actually getting called, since from the looks of things, it is not. The reason for this is because you don't register your submit handler when creating the form (or your validate handler, for that matter). Add these lines just before the return in your `searchsae_nameform()' function to register the handlers: $form['#validate'] = array('searchsae_nameform_validate'); $form['#submit'] = array('searchsae_nameform_submit'); Quote Link to comment https://forums.phpfreaks.com/topic/205170-drupal-trying-to-echo-data-but-nothing-happens/#findComment-1077806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.