douzuita7325 2017-04-05 11:59
浏览 38

使用链接/按钮按字母顺序对SQL数据库进行排序

Hello scripterfriends,

I'm working on a project where I need to sort a row in alphabetical order. After searching for some solutions I didn't find the one I was looking for. Lets say I need only the products that start with the letter "F". I want it like the picture below: https://gyazo.com/488ccc8fd2beaadbc96d687938e5a6ff

I need to be able to click the F and let it only show the product the start with the F.

The code I have so does the trick but I need to change the code in order to get another letter. This is the code I have so far:

<?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;
?>

Can someone help me out on this one???

Thanks in advance,

DigitalDentist

  • 写回答

2条回答 默认 最新

  • duanmao7553 2017-04-05 12:02
    关注

    Apply This query

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了