I'm sorry, but I'm just not knowledgeable enough to get it right!
It seems as if I either mess up the name column or the 'portkod' column in the table I create.
Winterbeefs second buffer suggestion displays a nice table where the 'portkod'strings are correct but the names wrong (since the vital join syntax found in the foreach statement is left out).
(I don't know how to run the foreach statement within the while loop in order to get the $buffer .= '<td>'.$row['surname'].'</td>'; correct.)
MrAlaska suggestions displays a nice table where the names are correct but not the 'portkod' column.
I'm not quite sure what I've done! If I echo out $portkod within the while loop it only finds the second element!
See: http://www.brfskalen11.org/claire/distinct.php
Here's what the code looks like at the moment. Hopefully someone can do some minor changes to get it right?
initdb($medlemmardb);
$svar = mysql_query("SELECT Andel, substring_index(Namn,' ',1) AS surname FROM Uppgifter WHERE Andel>=24 AND Andel <=48 GROUP BY Andel, surname ORDER BY surname ");
$db1="";
while($row=mysql_fetch_array($svar)){
$db1[$row['Andel']]=$row;
$people[$row['Andel']][] = $row['surname'];
$andel=$row['Andel'];
}
initdb($andelardb);
$resultat = mysql_query("SELECT Portkod FROM Uppgifter WHERE Andel=$andel");
$db2="";
while($row=mysql_fetch_array($resultat)){
$db1[$row['Andel']]=$row;
$portkod=$row['Portkod'];
}
echo "<table cellpadding=\"2\" border=\"1\">";
foreach($people as $k => $v) {
$people[$k] = join(', ', $v);
echo "<tr>";
echo "<td width=\"300\">";
echo $people[$k];
echo "</td>"."<td>";
echo $portkod;
echo "</td>"."</tr>";
}
echo "</table>";