My LEFT JOIN DB query results in the following:
ID-Name-File
1-Joe-joe1.pdf
1-Joe-joe2.pdf
2-John-john.pdf
3-Paul-NULL
What I want is:
1-Joe-joe1.pdf-joe2.pdf
2-John-john.pdf
3-Paul-NULL
I need it done in the query because I'm using CreateCSV.class, which takes a DB query and turns it into a CSV. But if someone knows how to change the class to accomplish this that would work to. Here's the code:
mysql_select_db($database_c, $c);
$query_Contacts = "SELECT * FROM Contacts LEFT JOIN PDFs ON Contacts.FileRef = PDFs.pdfFileRef ";
$Contacts = mysql_query($query_Contacts, $c) or die(mysql_error());
$row_Contacts = mysql_fetch_assoc($Contacts);
$totalRows_Contacts = mysql_num_rows($Contacts);
class CreateCSV{
function create($sql, $isPrintFieldName = false, $isQuoted = true){
$q = mysql_query($sql) or die("Error: ".mysql_error());
$csv = $head = $ctn = '';
$hasPrintHead = false;
while($r = mysql_fetch_assoc($q)){
if(!$hasPrintHead && $isPrintFieldName == true){
$csv_value = array();
foreach($r as $field => $value){
$csv_value[] = $field;
}
$hasPrintHead = true;
$csv .= implode(',', $csv_value)."\r\n";
}
//Print the content...
$aOpts_text = $csv_value = array();
foreach($r as $field => $value){
$csv_value[] = $isQuoted == true ? '"'.$value.'"' : $value;
}
$csv .= implode(',', $csv_value)."\r\n";
}
return $csv;
}
}
print CreateCSV::create($query_Contacts, true, false);