我在我的代码中添加了这个sql,
function devenir_client_dataforform() {
$type = $_POST['clientType'];
//$produitname = $_POST['produitname'];
$produitnid = $_POST['produitnid'];
$query = db_select('node', 'n');
$query->leftjoin('field_data_field_description_col_1', 'img', 'img.entity_id = n.nid');
$query->leftjoin('field_data_field_pdf_file_image', 'pdf', 'pdf.entity_id = n.nid');
$query->leftjoin('taxonomy_term_data', 't', 't.tid ='.$type);
$query->condition('n.nid', $produitnid, '=')
//->condition('t.tid', $type, '=')
->fields('n', array('title'))
->fields('t', array('name'))
->fields('pdf', array('field_pdf_file_image_fid'))
->fields('img', array('field_description_col_1_value'));
$result = $query->execute();
foreach ($result as $record) {
if(!empty($record->field_description_col_1_value)) {
$fid = $record->field_description_col_1_value;
$produitname = $record->title;
$pdf = $record->field_pdf_file_image_fid;
$tp = $record->name;
}
}
$file = file_load($pdf);
$uri = $file->uri;
$path = file_create_url($uri);
//$uri = image_style_path( $path);
$items[] = array(
"type" => $tp ,
"produitname" => $produitname,
"produitnid" => $produitnid,
"image" => $fid,
"pdf" => $path,
"typeid" => $type
);
return $items;
}
但在最后一步出现错误
PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第4行'WHERE(n.nid = NULL)'附近:SELECT n.title AS title,t.name AS名称,pdf.field_pdf_file_image_fid AS field_pdf_file_image_fid, img.field_description_col_1_value AS field_description_col_1_value FROM {node} n LEFT OUTER JOIN {field_data_field_description_col_1} img ON img.entity_id = n.nid LEFT OUTER JOIN {field_data_field_pdf_file_image} pdf ON pdf.entity_id = n.nid LEFT OUTER JOIN {taxonomy_term_data} t ON t.tid = WHERE(n.nid = :db_condition_placeholder_0);数组([:db_condition_placeholder_0] => )在devenir_client_dataforform()中(/home/dotit_bh/bh-website.dotit.mobi/sites/all/modules/devenir_client/devenir_client.module的第189行)。
答案 0 :(得分:0)
SQL Query的这一部分出错:
WHERE (n.nid = NULL)
更正SQL查询:
WHERE (n.nid is NULL)
你应该重写你的剧本:
$nid_operator = ($produitnid ? '=' : 'is');
$query->condition('n.nid', $produitnid, $nid_operator)
//->condition('t.tid', $type, '=')
->fields('n', array('title'))
->fields('t', array('name'))
->fields('pdf', array('field_pdf_file_image_fid'))
->fields('img', array('field_description_col_1_value'));