我有问题按不同类别的书排序表值,我有10种类别的书。 类别在名为“类别”的表中被提及为(1,2,3,... 10),并且每个类别包含超过100本书。
我只想从我的数据库中按一个类别(例如1)对书籍进行排序,并忽略所有其他类别。 我使用了以下php代码,但它将结果排序为整个列“类别”,这意味着所有类别都是逐个排序的 我只想按单一类别对数据进行排序。
$orderby = "ORDER BY books.category DESC";
$addparam = "";
if ($_GET["incldead"] == 2)
$wherea[] = "visible = 'yes'";
$res = mysql_query("SELECT COUNT(*) FROM books $where") or die(mysql_error());
$row = mysql_fetch_array($res,MYSQL_NUM);
$count = $row[0];
if ($count)
{
$pager = pager($booksperpage, $count, "browse.php?" . $addparam);
$query = "SELECT books.id, books.category, books.name, books.times_completed, books.size, books.added, books.type, books.comments,books.numfiles,books.filename,books.owner,IF(books.nfo <> '', 1, 0) as nfoav," .
"categories.name AS cat_name, categories.image AS cat_pic, users.username FROM books LEFT JOIN categories ON category = categories.id LEFT JOIN users ON books.owner = users.id $where $orderby {$pager['limit']}";
$res = mysql_query($query) or die(mysql_error());
以上代码的输出类似于以下内容:
我想要的输出:
请指导我如何修改上面的PHP代码......