1

我用一个看起来像这样的 sql 查询创建了这个表

$result = mysql_query("SELECT * FROM 5050goosedown");

echo "<table border='0' width='975'>
<tr>
<th width='12.5%'>name:</th>
<th width='12.5%'>width:</th>
<th width='12.5%'>height:</th>
<th width='12.5%'>fill:</th>
<th width='12.5%'>our fill:</th>
<th width='12.5%'>old price:</th>
<th width='12.5%'>price:</th>
</tr>";

$i = 1;
while($row = mysql_fetch_array($result)){
    echo "<tr bgcolor='#F5F5F5'>";
  if($i%2 == 0){
      echo "<tr bgcolor='#E5E5E5'>";
  }
  $i++;

  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['width'] . "</td>";
  echo "<td>" . $row['height'] . "</td>";
  echo "<td>" . $row['normal_fill'] . "</td>";
  echo "<td>" . $row['our_fill'] . "</td>";
  echo "<td>" . $row['old_price'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo '<td bgcolor=#FFFFFF><form method="post" action=""><input type="hidden" name="goosedown_id" value="'.$row['goosedown_id'].'" /><input type="submit" name="sumbit" value="Delete" /></form></td>';
  echo "</tr>";
  }
echo "</table>";

?>

我想知道以特定顺序显示表中项目的最佳方法是什么,因为目前是按字母顺序显示。但是,我希望它按大小顺序显示,., single, super single, queen, king, super king……</p>

我只是不知道如何尝试这个。您认为我可能需要在数据库中添加另一个条目吗?

这就是表格的样子.. 如您所见,有一个部分可以让人们输入自己的值

在此处输入图像描述

mysql

CREATE TABLE `5050goosedown` (
    `goosedown_id` int(11) unsigned NOT NULL auto_increment,
    `name` varchar(100) NOT NULL default '',  
    `width` int(8),
    `height` int(8),
    `normal_fill` int(8),
    `our_fill` int(8),
    `old_price` DECIMAL(3,2),
    `price` DECIMAL(3,2), 
    PRIMARY KEY  (`goosedown_id`)
    ) TYPE=MyISAM;
4

1 回答 1

3

但是我希望它按大小顺序显示,即单人、超级单人、皇后、国王、超级国王……</p>

然后试试这个:

ORDER BY
  CASE Size
    WHEN 'sigle' THEN 0 
    WHEN 'super' THEN 1
    WHEN 'single' THEN 2
    WHEN 'queen' THEN 3
    ...
  END , Name
于 2012-10-03T07:50:20.773 回答