ROW = SELECT * FROM table (example)
you get back
www.myfunplace.com amusement
www.barneyandfriends.com amusement
www.tellytubbies.com amusement
www.espn.com sports
www.thumbwrestling.com sports
now you output the type you come across first
echo "Amusement";
now you are calling your second loop
LINK = SELECT * FROM table WHERE type='amusement'
you get
www.myfunplace.com amusement
www.barneyandfriends.com amusement
www.tellytubbies.com amusement
however, NOW when you loop, you are calling ROW['url'] which will be the same since it hasnt iterated yet so you get
echo "www.myfunplace.com";
echo "www.myfunplace.com";
echo "www.myfunplace.com";
first loop iterates... you get
echo "Amusement";
second loop
echo "www.barneyandfriends.com";
echo "www.barneyandfriends.com";
echo "www.barneyandfriends.com";
first loop again
echo "Amusement";
second loop
echo "www.tellytubbies.com";
echo "www.tellytubbies.com";
echo "www.tellytubbies.com";
first loop again
echo "Sports";
second loop
echo "www.espn.com";
echo "www.espn.com";
echo "www.espn.com";
first loop
echo "Sports";
second loop
echo "www.mlb.com";
echo "www.mlb.com";
echo "www.mlb.com";
exit loops
make sense?
and heres's the code fixed... from what I see wrong...
<?
$sql = 'SELECT * from links ORDER BY type asc';
$query = mysql_query($sql) or die ("error");
while ($row=mysql_fetch_array($query)) {
echo '<u>'.$row['type'].'</u>';
echo '<br><br>';
$sql2 = "SELECT * from links where type='".$row['type']."'";
$query2 = mysql_query($sql2) or die ("error");
while ($link=mysql_fetch_array($query2)) {
echo "<a href=\"".$link['url']."\" target=\"_BLANK\">".$link['url'].'</a>';
echo '<br>';
}
echo '<br><br>';
}
?>