Script
<!--?php
/*
$select=db_query("SELECT u.name,u.uid FROM `users` u inner join users_roles r on r.uid=u.uid WHERE r.rid=4 ");
while ($result=db_fetch_array($select)){
$name=ucwords($result['name']);
$uid=$result['uid'];
$update ="update users set name ='".$name."' WHERE uid=".$uid;
$res=db_query($update);
}
*/
/*
$filename="sites/default/files/Export_article.csv";
$fp = fopen($filename, "w");
$res = mysql_query("
SELECT node.nid AS Id,
node.title AS Article,
node.title AS Keywords,
node_data_field_issue_nid.field_deck_value AS Subtitle,
u.name as first_name,
u.name as middle_name ,
u.name as last_name ,
concat ('Volume ',node_node_data_field_issue_nid_node_data_field_year.field_volumenumber_value) as Volume,Concat('Issue ',node_node_data_field_issue_nid_node_data_field_year.field_issuenumber_value ) as Issues ,
node_node_data_field_issue_nid_node_data_field_year.field_year_value AS Year_of_Issue,
node_node_data_field_issue_nid.title AS Issue,
concat('http://www.americanheritage.com/' ,al.dst) as Webaddress
FROM node node
LEFT JOIN content_type_article node_data_field_issue_nid ON node.vid = node_data_field_issue_nid.vid
LEFT JOIN node node_node_data_field_issue_nid ON node_data_field_issue_nid.field_issue_nid_nid = node_node_data_field_issue_nid.nid
LEFT JOIN content_type_issue node_node_data_field_issue_nid_node_data_field_year ON node_node_data_field_issue_nid.vid = node_node_data_field_issue_nid_node_data_field_year.vid
LEFT JOIN content_field_art_contributor node_data_field_art_contributor ON node.vid = node_data_field_art_contributor.vid inner join users u on u.uid=node_data_field_art_contributor.field_art_contributor_uid inner join users_roles r on r.uid=u.uid inner join url_alias al ON al.src = CONCAT('node/',node.nid)
WHERE node.type in ('article') and r.rid=4 order by Article ASC");
// fetch a row and write the column names out to the file
$row = mysql_fetch_assoc($res);
$line = "";
$comma = "";
foreach($row as $name =-->
<p>$value) { $line .= $comma . '"' . str_replace('"', '""', $name) . '"'; $comma = ","; } $line .= "\n"; //fputs($fp, $line); // remove the result pointer back to the start mysql_data_seek($res, 0); // and loop through the actual data while($row = mysql_fetch_assoc($res)) { $nid=$row['Id']; $row['Keywords']=''; $query_key=mysql_query("select DISTINCT(td.name) from node n inner join term_node tn ON n.nid = tn.nid LEFT JOIN term_data td ON tn.tid = td.tid where n.nid=$nid and td.vid =7"); while($rows = mysql_fetch_assoc($query_key)) { $row['Keywords'] .= $rows['name'].", "; } $row['Keywords'] = rtrim($row['Keywords'],", "); $concatt= $row['Volume'].", ".$row['Issues']; $row['Volume']=$concatt; $row['Subtitle']= strip_tags($row['Subtitle']); $author =$row['first_name']; $row_author=explode(" ",$author); $row['first_name']=ucwords($row_author[0]); if (empty($row_author[2])){ $row['middle_name']=''; $row['last_name']=ucwords($row_author[1]); } else { $row['middle_name']=ucwords($row_author[1]); $row['last_name']=ucwords($row_author[2]); } //echo "</p>
<pre>
";
// print_r($row);
//echo "</pre>
<p>"; $line = ""; $comma = ""; foreach($row as $value) { $line .= $comma . '"' . str_replace('"', '""', $value) . '"'; $comma = ","; } $line .= "\n"; // fputs($fp, $line); } fclose($fp); */ ?></p>