如何对不同表中的数据进行排序


How to order data from different table with relation?

为什么所有用户都提交相同的状态?

我有2张桌子,anggotastatus

我想从anggota表中获取一些数据并在home.php中使用它。

我正在使用下面的查询。

当我提交状态时,所有用户都会输出相同的状态,即使在数据库表中每个用户的状态也不同。

// my query:
$query=$dbc->query("select 
    anggota.username, anggota.name, anggota.pp, status.status 
    FROM status, anggota 
    ORDER BY status.id_stat = anggota.id_anggota DESC");`
状态

和状态表

您需要一个 where 子句来匹配正确 ID 上的状态和 anggota 表。不确定您要用"排序方式"完成什么,您可能需要对不同的列进行排序。

最好使用内部连接:

select a.username, a.name, a.pp, s.status 
    FROM status s 
    inner join anggota a on a.{what_ever_the_status_id_column_is} = s.{whatever_the_id_column_is} 
ORDER BY {columns_i_want_to_sort_on} DESC