简体   繁体   English

订购mysqli / PHP,如何添加更多订购者?

[英]ORDERING mysqli/PHP, how to add more ordering by?

May be stupid question, but I'm not sure how to extend this code to order for example by published name, by size, by name and etc, just make more ordering buttons. 可能是个愚蠢的问题,但是我不确定如何扩展此代码以按发布的名称,按大小,按名称等的顺序进行排序,只需创建更多的排序按钮即可。

This is code: 这是代码:

$query ="SELECT newsvid.id, newsvid.addName, newsvid.vidTitle, newsvid.url, newsvid.vidSD, newsvid.published, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2, videoinformation.vidZanr3, videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidTime  FROM newsvid, videoinformation WHERE newsvid.id = videoinformation.id";
$order = isset($_GET['order']) ? $_GET['order'] : 'ASC';
$goodParam = array("ASC", "DESC");

if (in_array($order, $goodParam)) {
if($order == 'ASC'){
     $query .= " ORDER BY newsvid.id ASC"; 
}else{
     $query .= " ORDER BY newsvid.id DESC"; 
    }
}

And this is my buttons: 这是我的按钮:

<a href="view.php?order=ASC">ASC</a> 
<a href="view.php?order=DESC">DESC</a>

PS I use samples from internet and adopt to my website and now can't extended, not sure how. 附言:我使用来自互联网的样本并采用到我的网站,现在无法扩展,不确定如何。

Thank you 谢谢

What exactly I need to change in php code to use this links? 我到底需要更改php代码才能使用此链接?

<a href="view.php?order=ASC">ASC</a> 
<a href="view.php?order=name">BY Name</a>
<a href="view.php?order=year">By Year</a>
<a href="view.php?order=published">By Publishing</a>
<a href="view.php?order=size">By Size</a>

DO I have to using like this?? 我必须像这样使用吗?

if (in_array($order, $goodParam)) {
if($order == 'ASC'){
     $query .= " ORDER BY newsvid.id ASC"; 
}else if{
     $query .= " ORDER BY newsvid.vidTitle DESC"; 
}else if{
     $query .= " ORDER BY newsvid.published DESC"; 
}else{
     $query .= " ORDER BY videoinformation.vidZard DESC"; 
    }
}

You can use more than one ORDER BY like that: 您可以像这样使用多个ORDER BY

ORDER BY newsvid.id ASC, newsvid.addName DESC

That sort first the ID and with 2 equal ID the Name. 首先对ID排序,对ID等于2的ID排序。

If you just try to add new sort, you just can change the name in your ORDER BY ... 如果您只是尝试添加新的排序,则可以在ORDER BY更改名称...

You can do: 你可以做:

if($order == 'ASC'){
     $query .= " ORDER BY newsvid.id ASC"; 
} elseif ($order == 'name') {
     $query .= " ORDER BY newsvid.addName ASC"; 
} elseif ($order == 'year') {
     $query .= " ORDER BY newsvid.vidYear ASC"; 
}

You should read up on general SQL. 您应该阅读常规SQL。 ORDER BY can take multiple arguments, like ORDER BY id, date_created, upvotecount . ORDER BY可以接受多个参数,例如ORDER BY id, date_created, upvotecount

Also: SQL multiple column ordering 另外: SQL多列排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM