Php 如何根据预定义的顺序显示MySQL结果关联数组?
我想使用PHP获取MySQL中存储的类别列表,并根据用户定义的顺序对它们进行排序。下面是代码现在的工作方式: 主文件Php 如何根据预定义的顺序显示MySQL结果关联数组?,php,html,mysql,Php,Html,Mysql,我想使用PHP获取MySQL中存储的类别列表,并根据用户定义的顺序对它们进行排序。下面是代码现在的工作方式: 主文件 <?php $categoryList = getCategoryList(); $categoriesPerRow = 4; $numCategory = count($categoryList); $columnWidth = (int)(100 / $categoriesPerRow); if ($numCateg
<?php
$categoryList = getCategoryList();
$categoriesPerRow = 4;
$numCategory = count($categoryList);
$columnWidth = (int)(100 / $categoriesPerRow);
if ($numCategory > 0) {
$i = 0;
$c = 0;
for ($i; $i < $numCategory; $i++) {
//We skip the dragster category.
if($categoryList[$i]['name'] == "Dragsters"){
continue;
}else{
if ($c % $categoriesPerRow == 0) {
echo '<tr style=\"vertical-align:top;\">';
}
// we have $url, $image, $name, $price
extract ($categoryList[$i]);
echo "<td width=\"$columnWidth%\" align=\"center\" style=\"vertical-align:top;\"><a href=\"$url\"><img src=\"$image\" border=\"0\"><br>$name</a><br></td>\r\n";
if ($c % $categoriesPerRow == $categoriesPerRow - 1) {
echo '</tr>';
}
}
$c++;
}
if ($i % $categoriesPerRow > 0) {
echo '<td colspan="' . ($categoriesPerRow - ($i % $categoriesPerRow)) . '"> </td>';
}
} else {
?>
<tr><td width="100%" align="center" valign="center">No categories yet</td></tr>
<?php
}
?>
我考虑过制作一个JQuery界面,用户可以在其中拖动和排列,然后保存类别的显示顺序。我认为数据库中的信息可以是每个类别都有一个存储订单号的字段。然后可以使用该订单号对类别进行排序。使用PHP实现这一点最有效的方法是什么?愚蠢的我,我已经弄明白了
SELECT cat_id, cat_name, cat_image
FROM tbl_category
WHERE cat_parent_id = 0
ORDER BY cat_order
cat_order是一个表示其在顺序中的位置的数字。jquery设计将允许用户订购。jquery与
seq\u no
对照cat\u id
听起来不错;仅适用于单个用户。祝你好运
SELECT cat_id, cat_name, cat_image
FROM tbl_category
WHERE cat_parent_id = 0
ORDER BY cat_order