[英]Display HTML table from SQL DB in custom order
I have created this table with a sql query that looks like this 我用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>";
?>
I was wondering what would be the best way to go about displaying the items in the table in a specific order because at the moment is is displaying in alphabetical order. 我想知道以特定顺序显示表格中的项目的最佳方式是什么,因为目前按字母顺序显示。 However, I would like it to display in a order of size, ie ., single, super single, queen, king, super king… 但是,我希望它以大小的顺序显示, 即单身,超级单身,女王,国王,超级王......
I just dont know how to attempt this. 我只是不知道如何尝试这个。 Do you think maybe I need another entry in the database? 您认为我可能需要在数据库中输入其他条目吗?
this is what the table looks like.. as you can see there is a section where people can enter their own values 这就是表格的样子......正如你所看到的那样,人们可以输入自己的价值观
mysql 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;
However I would like it to display in a order of size, ie, single, super single, queen, king, super king… 但是我希望它以大小的顺序显示,即单个,超级单身,女王,国王,超级国王......
Then try this: 然后尝试这个:
ORDER BY
CASE Size
WHEN 'sigle' THEN 0
WHEN 'super' THEN 1
WHEN 'single' THEN 2
WHEN 'queen' THEN 3
...
END , Name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.