Hallo,
I’m struggeling with some table joins and listings. I have managed to output a list but when it’s supposed to show a list of artists and curators it duplicates the exhibit name for each artist. I have tried to make it work as with the gallery name (saveName) but it’s not making any difference.
I’m not sure if that’s the answer, maybe it’s in the SELECT and JOINS? Or should it be a count of artists with a FOREACH inside the result array?
Here is what I’m looking for:
Gallery name1
Gallery adress, etc.
dates exhibit name1: Artist: artist1, artist2, artist3. Kurator: curator1. Info: some info
dates exhibit name2: Artist: artist1, artist2. Kurator: curator 1, etc.
…
Gallery name2
Gallery adress, etc.
dates exhibit name1: Artist: artist1, artist2, artist3. Kurator: curator 1
etc.
Any help would be greatly appreciated.
// View of gallery, exhibits and partisipants in tables
$row = 1;
$saveName = '';
$saveTitle = '';
$result = mysql_query(
"SELECT p.id
, p.title
, p.info
, p.galleryid
, p.start_date
, p.end_date
, p.date
, c.id
, c.galleryname
, c.address
, a.aname
, a.exhibitid
, k.cname
, k.exhibitid
FROM exhibit AS p
LEFT JOIN artist AS a ON p.id=a.exhibitid
LEFT JOIN curator AS k ON p.id=k.exhibitid
INNER JOIN gallery AS c
ON p.galleryid=c.id
ORDER BY c.galleryname, p.start_date" );
while($list = mysql_fetch_array($result)) {
$gname = $list['galleryname'];
$adr = $list['address'];
$start = $list['start_date'];
$end = $list['end_date'];
$timestamp = strtotime($start);
$start = date("d.m.y",$timestamp);
$timestamp = strtotime($end);
setlocale(LC_TIME, "no_NO.ISO_8859-1");
$end = date("d.m.y",$timestamp);
$title = $list['title'];
$info = $list['info'];
$date = $list['date'];
$timestamp = strtotime($date);
$date = date("d.m.y",$timestamp);
setlocale(LC_TIME, "no_NO.ISO_8859-1");
$art = $list['aname'];
$cur = $list['cname'];
if ($gname != $saveName && $title != $saveTitle) {
$result_array[] = "<table class='galleryname'><tr><td class='gname'>$gname</td></tr><tr><td class='gen'>$adr</td></tr></table><table class='exh'><tr><td class='dato'>$start - $end ($date)</td><td class='title'>".$list['title'].", " . $list['aname'] . ", kurator: $cur</td><td class='info'>$info</td></tr></table>";
$saveName = $gname;
$saveTitle = $title;
} else {
$result_array[] = "<table class='exh'><tr><td class='dato'>$start - $end ($date)</td><td class='title'>".$list['title'].", " . $list['aname'] . ", kurator: $cur</td><td class='info'>$info</td></tr></table>";
}
}
$result_final = "<table class='list'><tr>\
";
foreach($result_array as $cvtext) {
if($counter == $row) {
$counter = 1;
$result_final .= "\
</tr>\
<tr>\
";
}
else $counter++;
$result_final .= "\ <td>" . $cvtext . "</td>\
";
}
if($counter) {
if($rows) $result_final .= "\ <td colspan='".($row-$counter)."'></td>\
";
$result_final .= "</tr></table>";
}
echo $result_final;