What I am trying to accomplish...

  • Two CCK content types: volunteer and summary
  • When volunteer is submitted, use volunteer: field_update to compute and update summary: field_total_hours.

The error message is...

* warning: implode() [function.implode]: Invalid arguments passed in /path_to/modules/node/node.module on line 565.

* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /path_to/includes/database.mysqli.inc on line 154.

Another post on a different issue with the same error said: This kind of error seems related to invoking a node_load with an empty node id.

  1. Am I using the correct method for a computed field to get the current user id?
  2. Do you see anything wrong with the node_load part of my code in the first section shown below?
  3. I cannot comment on the query statement mentioned in the second part of the error message. I don't know what triggers it.

This is my computed code.

// Get the current User's id number
global $user;
$uid = $user->uid;

// Load the summary node
$nid = db_query("SELECT nid FROM {content_type_myhours_summary} smry WHERE smry.field_myhours_user_uid = %d", $uid);

$user_summary = node_load($nid);


// Get the total of all hours submitted
$records = db_query("
SELECT SUM(IF(LEFT(d.field_myhours_date_value,4) = YEAR(CURDATE()), (vol.field_hours_volunteer_service_value + vol.field_hours_volunteer_travel_value), 0)) AS ty,
 SUM(IF(LEFT(d.field_myhours_date_value,4) != YEAR(CURDATE()), (vol.field_hours_volunteer_service_value + vol.field_hours_volunteer_travel_value), 0)) AS prev
 FROM {content_type_myhours_volunteer} vol
 LEFT JOIN {node} n ON vol.nid = n.nid
 LEFT JOIN {content_field_myhours_date} d ON n.nid=d.nid
 WHERE n.uid = %d", $uid);

// Process the data
while ($totals = db_fetch_object($records)) {
   // Calculations & processes omitted to save space.

   // Set the new total hours values
   $user_summary->field_volunteer_ty_value = $totals->ty;
   $user_summary->field_volunteer_prev_value = $totals->prev;
}

// Save the summary node
node_save ($user_summary);

Comments

Moonshine’s picture

That is the correct way to get at the current user's UID, and you can send in the NID directly to node_load (assuming you're always going to have one to send in).

The first thing that catches my eye is that db_query is not going to just return the nid variable as you are thinking. It returns a result set that you can walk through with functions like db_fetch_array or db_fetch object:

http://api.drupal.org/api/function/db_fetch_array/5
http://api.drupal.org/api/function/db_fetch_object/5

For trouble shooting computed field issues it's also good to remember that you can put code like drupal_set_message() in your code to help output variables for debugging. If you have devel installed then dpr() is even better.

colan’s picture

Component: User interface » Code
Status: Active » Closed (won't fix)

Version 5 is no longer supported.