Run php alphabetical pointer per click
I want to create an alphabetical index of content in a mysql database.
the second part is not my problem, I have the code - these are buttons, and when pressing o one of the letter buttons, run a mysql query with letter.
I have coded the shape for each letter, for example:
<form action="query.php?x=A" method="get">
<input type=submit value="A">
</form>
change "A"
with every letter.
then in query.php
I have $_get["x"]
and with it I run the query.
So I have 27 forms, but this is very messy, is there any other way to write it?
and if possible, is there a way to run the mysql query on the same page? (to be able to start another letter.)
source to share
Simple and a little rough, but it works ...
The idea is to have 26 submit buttons with a different letter meaning in each.
<?php
if (isset($_GET['theLetter'])) {
if ( ctype_alpha($_GET['theLetter'])
&& strlen($_GET['theLetter']) === 1) {
$theLetter = $_GET['theLetter'];
echo '<br />', 'A valid letter of: ', $theLetter, ' was input.';
}
else {
echo '<br />', 'Incorrect input: ', htmlentities($_GET['theLetter']), ' was input.';
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<form action="" method="get">
<?php $letter = ORD('a'); ?>
<?php while ($letter <= ORD('z')): ?>
<input type="submit" name="theLetter" value="<?= CHR($letter) ?>">
<?php $letter++; ?>
<?php endwhile; ?>
</form>
</body>
</html>
source to share