Hello,
I'm a bit of a newcomer to PHP and am having an issue I can't overcome.
I've read some great posts on the issue of grouping results on this forum
1 and can happily display results under a common variable. The problem occurs as I want to display the common variable after the grouped results.
I'm attempting to write out the results of a query for journal articles in a citation format that lists authors before the journal title (common variable).
I have 3 tables.
Authors
aID | LastName
1 | Smith
2 | Jones
3 | Jacks
Pubs
pID | pTitle
1 | Article 1
2 | Article 2
AuthorsJoin
pID | aID
1 | 1
1 | 2
1 | 3
I'd like to output my results in the format
Jacks, Jones, Smith Article 1
I can currently output as the following using the code below.
Article 1 Jacks, Jones, Smith -
SELECT
-
LastName,
-
AuthorsJoin.aID,
-
Authors.aID,
-
AuthorsJoin.pID,
-
Pubs.pID,
-
PubTitle
-
FROM Authors, AuthorsJoin, Pubs
-
WHERE Authors.aID=AuthorsJoin.aID
-
AND AuthorsJoin.pID=Pubs.pID
-
ORDER BY Pubs.PubTitle
-
-
<?PHP
-
$ptitle = "";
-
while ($row = mysql_fetch_array($result))
-
{
-
if (strcmp( $ptitle, $row['PubTitle']))
-
{
-
echo "<br /><strong>$ptitle</strong> ";
-
$ptitle = $row['PubTitle'];
-
}
-
echo $row['LastName'].', ';
-
}
-
?>
-
So the above will let me output the grouped results under a common variable, but I need something that will let me output the common variable after the grouped results... is this even possible?
Any help would be most appreciated!
Keven