Loop over sql array
Posted: Wed Feb 15, 2012 4:12 pm
some of the code is Drupal specific i.e. db_query rather than mysql_query however my problem is a php problem.
I need to populate 'cck field data' shown in the code by looping through the mysql query. I hope you can help as i have drawn a blank on the drupa forums.
much appreciated,
Col
I need to populate 'cck field data' shown in the code by looping through the mysql query. I hope you can help as i have drawn a blank on the drupa forums.
much appreciated,
Col
Code: Select all
function emailspool_action(&$object, $context = array()) {
// get the uid from the object
$uid = $object->uid;
// get node data
$nodeid = $object->nid; // current node
// get values by from Query
$result = db_query("SELECT content_type_13_form.nid AS formNID,
node.title AS projectID,
`22_form_type`.title AS formType,
`22_integrated_team_without_pm`.roleName AS formRole,
`22_integrated_team_without_pm`.userName AS formUser,
`22_integrated_team_without_pm`.mail AS formEmail,
content_type_06_projects.field_06_proj_title_value AS formTitle,
`22_form_pm`.`name` AS formPM,
`22_form_author`.`name` AS formAuthor,
content_type_13_form.field_13_form_date_value AS formDate,
content_type_13_form.field_13_cnscore_value AS formScore,
`22_integrated_team_without_pm`.field_19_int_subscribe_value AS formSubscribe
FROM content_type_13_form INNER JOIN node ON content_type_13_form.field_13_form_projectid_nid = node.nid
INNER JOIN `22_form_pm` ON content_type_13_form.nid = `22_form_pm`.formNID
LEFT OUTER JOIN `22_integrated_team_without_pm` ON `22_form_pm`.`team.NID` = `22_integrated_team_without_pm`.teamNid
LEFT OUTER JOIN `22_form_type` ON content_type_13_form.nid = `22_form_type`.nid
INNER JOIN content_type_06_projects ON content_type_13_form.field_13_form_projectid_nid = content_type_06_projects.nid
INNER JOIN `22_form_author` ON content_type_13_form.nid = `22_form_author`.nid
WHERE content_type_13_form.nid = '%s'
AND `22_integrated_team_without_pm`.roleName <> 'Project Manager'", $nodeid);
//$myrow = db_fetch_array($result);
$myobject = db_fetch_object($result);
foreach (????????????????????) { // this is where i need help
// add node properties
$newNode = new StdClass();
$newNode->type = '22_email_spool';
$newNode->title = 'New Spool Item';
$newNode->uid = $uid;
$newNode->created = strtotime("now");
$newNode->changed = strtotime("now");
$newNode->status = 1;
$newNode->comment = 0;
$newNode->promote = 0;
$newNode->moderate = 0;
$newNode->sticky = 0;
// add CCK field data
$newNode->field_22_spool_formnid[0]['nid'] = $nodeid;
$newNode->field_22_spool_pm[0]['value'] = $myobject->formPM;
$newNode->field_22_spool_it_user[0]['value'] = $myobject->formUser;
$newNode->field_22_spool_cnscore[0]['value'] = $myobject->formScore;
$newNode->field_22_spool_it_email[0]['email'] = $myobject->formEmail;
$newNode->field_22_spool_projectid[0]['value'] = $myobject->projectID;
$newNode->field_22_spool_projecttitle[0]['value'] = $myobject->formTitle;
$newNode->field_22_spool_author[0]['value'] = $myobject->formAuthor;
$newNode->field_22_spool_formtype[0]['value'] = $myobject->formType;
$newNode->field_22_spool_subscribe[0]['value'] = $myobject->formSubscribe;
$newNode->field_22_spool_date[0]['value'] = $myobject->formDate;
// save node
node_save($newNode);
}