我想在mysql数据库的内容的字母索引。
第二部分不是我的问题,我所拥有的代码是按钮,并且,当按下一个字母按钮时,运行带有字母的mysql查询。
我为每个字母编写了一个表单,像这样:
<form action="query.php?x=A" method="get">
<input type=submit value="A">
</form>
改变"A"
的每一个字母。
然后在query.php
中,我有一个$_get["x"]
,并使用它运行查询。
那么,我有27个表单,但这是非常脏的,有其他的方式来写吗?
并且,如果可能的话,是否有任何方法在同一页面中运行mysql查询?(为了能再加一个字母)
简单,有点粗糙,但它的工作…
我们的想法是有26个提交按钮,每个按钮有不同的字母值。
<?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>
你可以试试下面的代码
<form action="query.php" method="post">
<input type="text" name="letter" />
<input type=submit>
在query.php中添加$_POST['letter']而不是$_GET['X']