I made a golf-dicitionary on a site a long while ago. Here is how I did it:
<?php
// array of alphabet using the range() function:
$letters = range('a','z');
// loop through the letters:
foreach($letters as $value)
{
echo '<a href="?page=dictionary&letter=' . $value . '">' . strtoupper($value) . '</a> |' . "\n";
}
// grab letter from URL
if (isset($_GET['letter']))
{
$letter = trim(strtolower($_GET['letter']));
}
else {
$letter = 'a';
}
// page heading
echo '<h2>' . strtoupper($letter) . '</h2>';
// required db connection info
require("../inc/db.inc.php");
// Connect to mysql and select db
$my_db = connecting2_db();
// grab start from the URL
if(isset($_GET['start']))
{
$start = trim($_GET['start']);
}
else {
$start = 0;
}
// db Query
$sql = "SELECT * FROM dictionary WHERE alpha = '$letter' ORDER BY id ASC LIMIT " . $start . ", 5";
// Connect or die
$result = mysql_query($sql, $my_db) or db_mysql_die();
// if there are no results for this letter:
if (mysql_num_rows($result) <= 0)
{
echo '<p>Sorry. No items were found for the letter: <strong>' . $letter . '</strong>.</p>';
}
// else, there are results:
else {
while ($row = mysql_fetch_array($result))
{
echo '<p><span class="bold">' . $row['term'] . ':</span> ' . $row['definition'] . '</p>' . "\n";
}
}
// previous and next links
$query = "SELECT count(*) as count FROM dictionary WHERE alpha = '$letter'";
$result = mysql_query($query,$my_db);
$row = mysql_fetch_array($result);
$numrows = $row['count'];
// Previous Link.
if($start > 0 || $numrows > ($start + 10))
{
echo '<p style="border-top:solid 1px #3a3936;margin:5px;">';
}
if($start > 0)
{
echo '<a href="' . $_SERVER['PHP_SELF'] . '?start=' . ($start - 5) . '&letter=' . $letter . '">Previous</a> ';
}
// Next Link.
if($numrows > ($start + 10))
{
echo '<a href="' . $_SERVER['PHP_SELF'] . '?start=' . ($start + 5) . '&letter=' . $letter . '">Next</a>';
}
echo '</p>';
// end SQL session
mysql_close();
?>
(I am not sure I would do it this way now, but I hope it helps you out a little...)