Hello, I’m having some problems with grabbing some information from my database and then looping through it. Here is what I have:
[php]//First My array of letters
$letters = array(‘A’,‘B’,‘C’,‘D’,‘E’,‘F’,‘G’,‘H’,‘I’,‘J’,‘K’,‘L’,‘M’,‘N’,‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’,‘X’,‘Y’,‘Z’);
//Next we have my query
$query = mysql_query(“SELECT id,forename,surname FROM customer ORDER BY surname”) or die(mysql_error());
//We’re going to loop through the array $letters
for($j=0;$j<26;$j++)
{
//echo a header for the letter
echo “
Names Beginning with $letters[$j]
”;//get the rows from the query
while($row = mysql_fetch_array($query))
{
//output all rows whose 'surname' starts with said letter
if($row['surname'][0] == $letters[$j])
{
echo "<a href='update.php?id=".$row['id']."'>".$row['forename']." ".$row['surname']."</a>";
echo "<br />";
}
}
}[/php]
Now what this code is displaying is the header for the letter A, followed by all the surnames beginning with A. It also shows the headers for B - Z, however it does not show any of the names for the surnames beginning with those letters.