Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用链接/按钮按字母顺序排序sql数据库_Php_Html_Sql_Alphabetical - Fatal编程技术网

Php 使用链接/按钮按字母顺序排序sql数据库

Php 使用链接/按钮按字母顺序排序sql数据库,php,html,sql,alphabetical,Php,Html,Sql,Alphabetical,各位编剧朋友好 我正在做一个项目,我需要按字母顺序对一行进行排序。在寻找一些解决方案后,我没有找到我正在寻找的解决方案。假设我只需要以字母“F”开头的产品。我希望它如下图所示: 我需要能够点击F,让它只显示产品的F开始 我所拥有的代码确实起到了作用,但我需要更改代码以获得另一个字母。这是我目前掌握的代码: <?php require_once 'config.php'; try { $sQuery = "SELECT receptnummer, receptnaam, recep

各位编剧朋友好

我正在做一个项目,我需要按字母顺序对一行进行排序。在寻找一些解决方案后,我没有找到我正在寻找的解决方案。假设我只需要以字母“F”开头的产品。我希望它如下图所示:

我需要能够点击F,让它只显示产品的F开始

我所拥有的代码确实起到了作用,但我需要更改代码以获得另一个字母。这是我目前掌握的代码:

<?php
require_once 'config.php';

try {
    $sQuery = "SELECT receptnummer, receptnaam, receptingredient, receptbereidingstijd, receptbereidingswijze, receptcategorie, receptbenodigdheden, receptserveertips, klantnummer
     FROM recept
     WHERE receptnaam LIKE '%f%' ORDER BY receptnaam";

    $oStmt = $db->prepare($sQuery);

    $oStmt->execute();

    if ($oStmt->rowCount() > 0) {
        echo '<table border="2">';
        echo '<thead>';
        echo '<td>receptnummer</td>';
        echo '<td>receptnaam</td>';
        echo '<td>receptingredient</td>';
        echo '<td>receptbereidingstijd</td>';
        echo '<td>receptbereidingswijze</td>';
        echo '<td>receptcategorie</td>';
        echo '<td>receptbenodigdheden</td>';
        echo '<td>receptserveertips</td>';
        echo '<td>klantnummer</td>';

        while ($aRow = $oStmt->fetch(PDO::FETCH_ASSOC)) {

            echo '<tr>';
            echo '<td>' . $aRow['receptnummer'] . '</td>';
            echo '<td>' . $aRow['receptnaam'] . '</td>';
            echo '<td>' . $aRow['receptingredient'] . '</td>';
            echo '<td>' . $aRow['receptbereidingstijd'] . '</td>';
            echo '<td>' . $aRow['receptbereidingswijze'] . '</td>';
            echo '<td>' . $aRow['receptcategorie'] . '</td>';
            echo '<td>' . $aRow['receptbenodigdheden'] . '</td>';
            echo '<td>' . $aRow['receptserveertips'] . '</td>';
            echo '<td>' . $aRow['klantnummer'] . '</td>';
            echo '</tr>';
        }
        echo '</table>';
    } else {
        echo 'helaas, geen gegevens gevonden';
    }

} catch (PDOException $e) {
    $sMsg = '<p>
    Regelnummer: ' . $e->getLine() . '<br/>
    Bestand: ' . $e->getFile() . '<br/>
    Foutmelding: ' . $e->getMessage() . '
</p>';

    trigger_error($sMsg);
}
$db = null;
?>

有人能帮我解决这个问题吗

提前感谢,

数字牙医

应用此查询

 $sQuery="SELECT receptnummer, receptnaam, receptingredient, receptbereidingstijd, receptbereidingswijze, receptcategorie, receptbenodigdheden, receptserveertips, klantnummer
 FROM recept
 WHERE receptnaam LIKE 'f%' ORDER BY receptnaam";

整个技巧就在这个查询中:

$sQuery="SELECT receptnummer, receptnaam, receptingredient, receptbereidingstijd, receptbereidingswijze, receptcategorie, receptbenodigdheden, receptserveertips, klantnummer
 FROM recept
 WHERE receptnaam LIKE '%f%' ORDER BY receptnaam";
您只需将
中的
f
替换为变量,如“%f%”
,该变量可以从POST/get请求中获取


编辑:正如其他人提到的,您可能应该将
%f%
替换为
f%
,除非您要查找的单词仅包括字母f,而不仅仅是以字母f开头。

如果某个单词以“f”开头删除第一个百分比登录
'%f%'
是fred是对的%f%表示前面的任何内容,然后是“f”,然后是后面的任何内容如果在单击字母之前使用like命令,是否所有记录都已显示在客户端?如果是这样的话,似乎过滤客户端会更好,因为不需要再次访问服务器。但是,如何才能将其他变量链接到带有该特定字母的链接或按钮?但无论如何,是否可以使字母“a”显示所有带有a的内容,而字母“B”显示所有带有B的内容,等等。比如在这样的菜单中:“a | B | C | D |…”我不确定我是否理解正确。是否需要按字母顺序显示整个表格的内容?如果是这样,您将不得不运行多个查询。制作一个字符串
$alphabet='abcdefghijklmnopqrstuvxyz'
,然后将代码放入该字符串中每个字符的FOR循环中。不要忘记做
mysqli\u next\u结果($database)在每次查询之后,您可以发送一个新的查询。我自己已经解决了;)无论如何谢谢你的帮助!