This should work if all of the categories are stored in an array
//Define the first letter that you want to focus on
$letter = 'b';
//Store all items in an array
$categories = array('Books', 'Marketing', 'TV', 'Radio', 'Computers');
//Loop thru
for($i=0;$i<count($categories);$i++)
{
//This might be case sensitive, so lower the items and get the first letter of it
if(strtolower(substr($categories[$i], 0, 1)) == $letter)
{
echo $categories[$i].'<br />';
}
}
OR, if you're storing all of them in MySQL
//Connect to MySQL
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
//Query the DB for all categories beginnng with a particular letter
$query = "SELECT * FROM table WHERE category LIKE '".$letter."%'";
$result = mysqli_query($link, $query);
$count = mysqli_num_rows($result);
$i = 0;
while ($row = mysqli_fetch_assoc($result)) {
$categories[$i] = $row['category'];
$i++;
}
//Loop thru
for($i=0;$i<$count;$i++)
{
echo $categories[$i].'<br />';
}
You produce the exact same effect that's shown on the link you provided, you'll need more than just PHP; you'll need JS too. But, that's another task.