-1

On a (drupal 6 based) website that is used as a database to track product information:

I have a page that starts a number of SQL to correctly sort the data, but after a page edit of the product information, these SQL scripts don't start, and the new data isn't displayed properly.

If I go to admin/settings/performance everything reloads, the SQL scripts run and the page displays data as it should.

How do I get around having to after each edit.

I have tried: 1. admin/settings/performance Caching mode: Disabled

*maybe with caching disabled the page needs to reload each time - it didn't work

Minimum cache lifetime:

*changed to 1min - it didn't work

2. installed (seemingly perfectly suited to my purpose) module: Cache Exclude 6.x-2.2 https://drupal.org/project/cacheexclude

*this didn't seem to have any effect either


The SQL scripts are run from a tpl file for the page, there are many scripts which might be the problem, and it could definitely be done more efficiently. But previously I've been using scripts on the page successfully, its just the new ones that don't seem to work after an edit to the record/page

Here is the TPL - modified from the garland theme (not the full tpl):

<?php
drupal_add_css($directory .'/node-fixing.css');
//delta no match reordering
 db_set_active($db_name);
$qry = "drop table if exists deltanomatch;";

db_query($qry);
$qry = "create table deltanomatch as (

SELECT distinct content_field_itemnum.vid, content_field_itemnum.nid, content_field_itemnum.field_itemnum_value - 1 as delta, content_field_itemnum.field_itemnum_value, field_item_value,  field_remarks_value, field_trepair_value, field_tretail_value
FROM content_field_itemnum
left join content_field_item on content_field_itemnum.nid=content_field_item.nid and content_field_itemnum.delta=content_field_item.delta
left join content_field_remarks on content_field_itemnum.nid=content_field_remarks.nid and content_field_remarks.delta=content_field_item.delta
left join content_field_trepair on content_field_itemnum.nid=content_field_trepair.nid and content_field_remarks.delta=content_field_trepair.delta
left join content_field_tretail on content_field_itemnum.nid=content_field_tretail.nid and content_field_remarks.delta=content_field_tretail.delta
where content_field_itemnum.nid in (SELECT distinct nid
FROM content_field_itemnum
where (delta + 1)  != field_itemnum_value) and field_item_value is not null
order by nid desc, field_itemnum_value asc);";

db_query($qry);
$qry = "delete FROM content_field_item 
where nid in (select nid from deltanomatch);";

db_query($qry);
$qry = "delete FROM content_field_itemnum 
where nid in (select nid from deltanomatch);";

db_query($qry);
$qry = "delete FROM content_field_remarks 
where nid in (select nid from deltanomatch);";

db_query($qry);
$qry = "delete FROM content_field_trepair 
where nid in (select nid from deltanomatch);";

db_query($qry);
$qry = "delete FROM content_field_tretail 
where nid in (select nid from deltanomatch);";

db_query($qry);
$qry = "insert into content_field_item
select vid, nid, delta, field_item_value from deltanomatch;";

db_query($qry);
$qry = "insert into content_field_itemnum
select vid, nid, delta, field_itemnum_value from deltanomatch;";

db_query($qry);
$qry = "insert into content_field_remarks
select vid, nid, delta, field_remarks_value from deltanomatch;";

db_query($qry);
$qry = "insert into content_field_trepair
select vid, nid, delta, field_trepair_value from deltanomatch;";

db_query($qry);
$qry = "insert into content_field_tretail
select vid, nid, delta, field_tretail_value from deltanomatch;";
2

Never put logic in .tpl files, unless it's purely "display logic". Move your logic to hook_field_attach_submit() or use Computed Field if you want to reliably update field values. Or find any other way, as long as you keep business logic out of your themes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.