如何从关系不同的表中订购数据?

时间:2016-02-14 14:55:44

标签: php html mysqli

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

我有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");`

the status and status table

1 个答案:

答案 0 :(得分:0)

您需要一个where子句来匹配正确ID上的status和anggota表。不确定你要用“order by”来完成什么,你可能想要在不同的列上进行排序。

更好地使用内连接:

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