php - 我需要仅显示 mySQL 表中以 "250"前缀开头的记录

标签 php mysql filter html-table

我不需要显示所有记录,而是只过滤以“250”开头的记录。有没有办法更改我现有的表脚本以仅显示以“250”开头的记录?

<?php
$db = new mysqli("localhost", "XXXXXX", "XXXXXX", "naturan8_hero");
$query = "SELECT type, part_no, description, artwork, min, max, qty FROM cartons_current     LIMIT 0,100"; 
$result = $db->query($query, MYSQLI_STORE_RESULT);
$o = '<table id="tablesorter-demo" class="tablesorter" border="0" cellpadding="0" cellspacing="1"><thead><tr><th>TP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Item Number&nbsp;&nbsp; &nbsp; &nbsp;</th><th>Description</th><th>Artwork No.   </th><th class="hidden">PDF &nbsp; &nbsp;</th><th>Min &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Max &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th>Qty&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;</th>  </tr></thead><tbody>';
while(list($type, $part_no, $description, $artwork, $min, $max, $qty) = $result->fetch_row()) {
$o .= '<tr><td>'.$type.'</td><td class="ptn">'.$part_no.'</td><td>'.$description.'</td><td>'.$artwork.' &nbsp; &nbsp;</td><td class="hidden"><a href="/data/hero/upload/'.$part_no.'.pdf" target="_blank">Link &nbsp;</a></td><td align="right" class="min">'.$min.'</td><td align="right" class="max">'.$max.'</td><td align="right" class="quantity"> '.$qty.'</td></tr>';}
$o .= '</tbody></table>';
echo $o;
?>

最佳答案

尝试:

SELECT type, part_no, description, artwork, min, max, qty FROM cartons_current WHERE part_no like '250%'

或者:

从 cartons_current 中选择类型、零件编号、描述、艺术品、最小、最大、数量,其中 left(part_no,3) = '250'

关于php - 我需要仅显示 mySQL 表中以 "250"前缀开头的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10907027/

相关文章:

使用多个关键字的 Jquery Grep 和 Map Json

php - 扩展核心 symfony 表单 Bootstrap 主题

mysql - SQL 键、外键对于目的来说有点过于锁定

mysql - sql join 返回两个相同的值

java - 过滤器在 Glassfish 3.1.1 中不起作用

python - 如何解读TensorFlow的卷积滤波器和stridding参数?

php - 新选项卡中的 Codeigniter 加载 View

php - 阻止MySQL用空字符串更新列?

php - Android + 网站/服务器上的 Facebook 身份验证

mysql - sql_actions_Local_instance_MySQL56.log可以删除吗?