Monthly Archives: June 2010

Drupal “The connection was reset”

I used phpMyAdmin to browse to my database. Locate the `variable` table, then look for the following variable names: cache, page_compression, block_cache, preprocess_css, preprocess_js and reset them:

01 #reset the cache configuration
02 UPDATE `variable` SET `value` = 's:0:"";' WHERE `name` = 'cache' LIMIT 1;
03 UPDATE `variable` SET `value` = 's:0:"";' WHERE `name` = 'page_compression' LIMIT 1;
04 UPDATE `variable` SET `value` = 's:0:"";' WHERE `name` = 'block_cache' LIMIT 1;
05 UPDATE `variable` SET `value` = 's:0:"";' WHERE `name` = 'preprocess_css' LIMIT 1;
06 UPDATE `variable` SET `value` = 's:0:"";' WHERE `name` = 'preprocess_js' LIMIT 1;
07
08 #empty the cache tables (main ones)
09 TRUNCATE `cache`;
10 TRUNCATE `cache_block`;
11 TRUNCATE `cache_content`;

After issuing this commands my local site started working. From: http://ghita.org/drupal-the-connection-was-reset.html

Advertisements

Displaying the total number of results on the search page

First I added a preprocess_search_results function in my theme’s template.php file to generate the html to show on the search results page:

function zen_preprocess_search_results(&$variables) {

// define the number of results being shown on a page
$itemsPerPage = 10;

// get the current page
$currentPage = $_REQUEST['page']+1;

// get the total number of results from the $GLOBALS
$total = $GLOBALS['pager_total_items'][0];

// perform calculation
$start = 10*$currentPage-9;
$end = $itemsPerPage * $currentPage;
if ($end>$total) $end = $total;

// set this html to the $variables
$variables['zen_search_totals'] = "Displaying $start - $end of $total results";

}

Now, you can show this variable on the search results page by copying the search results template file (modules/search/search-results.tpl.php) into your theme folder and editing it.

<?php print $MYTHEME_search_totals; ?>
<!-- added line -->

<dl class="search-results <?php print $type; ?>-results">
<?php print $search_results; ?>
</dl>
<?php print $pager; ?>

<?php
function MYTHEME_preprocess_search_results(&$variables) {

// define the number of results being shown on a page
$itemsPerPage = 10;

// get the current page
$currentPage = $_REQUEST['page']+1;

// get the total number of results from the $GLOBALS
$total = $GLOBALS['pager_total_items'][0];

// perform calculation
$start = 10*$currentPage-9;
$end = $itemsPerPage * $currentPage;
if (
$end>$total) $end = $total;

// set this html to the $variables
$variables['MYTHEME_search_totals'] = "Displaying $start - $end of $total results";

}
?>

Now, you can show this variable on the search results page by copying the search results template file (modules/search/search-results.tpl.php) into your theme folder and editing it.

Here is the new contents of my modified file (minus the comments at the top):

<!-- NEW SEARCH RESULTS TOTALS: -->
<?php print $MYTHEME_search_totals; ?>

<!-- ORIG CONTENTS: -->
<dl class="search-results <?php print $type; ?>-results">
<?php print $search_results; ?>
</dl>
<?php print $pager; ?>

gradient spacer

Comments…

Nice snippet

I changed the variables a bit so they are using the t() function. This way, translators can change the display easily.

eg: t(‘Displaying @start – @end of @total results’, array(‘@start’ => $start, ‘@end’ => $end, ‘@total’ => $total));

Fantastic

Finding snippets that
a) work
b) are simple to implement
c) retain a separation of data from content
d) don’t hack core and
e) I get (the hardest condition to satisfy)

is like GOLD.
🙂
Thank you Eric London – I’ve credited you in my template.php
😉
Chris

Nice one

This is a great snippet–very clean and straightforward. Thanks for sharing!

Thank you !

This was indeed very easy to understand and very helpful! Thanks a lot!