简体   繁体   English

点击运行php字母索引

[英]Run php alphabetic index on click

I want to make an alphabetic index of content in a mysql database. 我想在mysql数据库中创建一个字母的内容索引。

the second part is not my problem, what I have code is the buttons, and, when pressing o one of the letter buttons, run a mysql query with the letter. 第二部分不是我的问题,我的代码是按钮,当按下其中一个字母按钮时,用字母运行一个mysql查询。

I have coded a form for every letter like this: 我已为每个字母编写了一个表格,如下所示:

<form action="query.php?x=A" method="get">
       <input type=submit value="A">
</form>

changing "A" with every letter. 用每个字母改变"A"

then in query.php I have a $_get["x"] and with it I run the query. 然后在query.php我有一个$_get["x"]并用它运行查询。

so, I have 27 forms, but that is very dirty, is there any other way to write it? 所以,我有27个表格,但这很脏,有没有其他方法可以写呢?

and, if its possible, is there any way to run the mysql query in the same page? 并且,如果可能的话,有没有办法在同一页面中运行mysql查询? (to be able to run another letter.) (能够再写一封信。)

Simple and a little crude but it works... 简单而有点粗糙,但它的工作原理......

The idea is to have 26 submit buttons with a different letter value in each. 这个想法是有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>

you can try this code 你可以尝试这个代码

<form action="query.php" method="post">
   <input type="text" name="letter" />
   <input type=submit>

in your query.php add $_POST['letter'] instead od $_GET['X'] 在你的query.php中添加$ _POST ['letter']而不是$ $ _GET ['X']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM