Jump to content

DRUPAL: Trying to echo data but nothing happens!


Z33M@N

Recommended Posts

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!'));
  
  }


}

 

 

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.