Greetings all,
I have been working on this with some others reading the forums on this site, but cannot get the final result to operate correctly.
I have a php page called test6.php and can be found here:
http://www.lithuaniangenealogy.org/test/test6.php
Initially, when you go to this page, the php code will display the entire contents of a the table in our database in an HTML table for viewing. This is the default view that I want.
However, I want to add the functionality that if a user clicks on a link by way of a letter in the alphabet, I want the page to reoder by the letter clicked (this is so people can search by the first letter of the surname instead of having to scroll through the entire list)
You will see initially, the full contents of the table and the alphabet links (generated with php code). However, when you click on a letter of the alphabet, the page will refresh but return an empty HTML table.
So, can a fresh set of eyes see where my problem is in the following code? I have tried changing this in multiple ways, but always ended up with parsing/db errors. This way works until you click on a letter. No error results, but you get an empty table no matter what letter you click on. Is it possible to modify the code (once fixed) to display "There are no surnames in our database beginnging with the letter $letter." result?
Thanks!
<?php
include("../../includes/test.inc");
$dbh=@mysql_connect ("$dbhost", "$dbuser", "$dbpass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");
$query = "SELECT * FROM testtable WHERE 'Name of Child' LIKE '$letter%' ORDER BY 'Name of Child'";
$result = mysql_query($query);
// Output letters as links: (Rem. ascii range from 65 to 90 are letters A to Z!)
for($x=65;$x<=90;$x++)
{
if ($x==ord($subsel)) echo "<b>".chr($x)."</b>";
else
echo "<a href=\"test6.php?letter=".chr($x)."\">".chr($x)."</a> ";
}
$letter = $_GET["letter"];
echo "<TABLE BORDER=1 cellpadding=5>";
echo "<tr bgcolor=\"#9999CC\">";
echo "<td width=18%><strong>Name of Child</strong></td>";
echo "<td width=20%><strong>Name(s) of Parents</strong></td>";
echo "<td width=25%><strong>Name(s) of Godparents</strong></td>\n";
echo "</tr>";
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><strong>{$row['Name of Child']}</strong><br> Baptismal Date:<em>{$row['Baptismal Date']}</em></td>";
echo "<td>{$row['Name of Parents']}</td>";
echo "<td>{$row['Name of Godparents']}</td>";
echo "</tr>";
}
echo "</TABLE>";
$today = date("l dS of F Y h:i a");
print "<CENTER>Today is $today (server time)</CENTER>";
?>