我有两个表:帐户和授权。
帐户表具有客户和代理的全名和ID。授权表具有该客户下的客户和代理的ID。 accounts表具有Full Name,以及代理和客户的id。
我不断获取代理商名称而不是客户名称。不确定如何解决这个问题!
更新:我能够获得正确的ID但仍未显示客户的姓名 代码:
//Query
$sql = "SELECT authorizations.customer_id, accounts.fullname
FROM authorizations
INNER JOIN accounts ON
authorizations.system_id = accounts.authorizating_customer
WHERE authorizations.agent_id = '$did'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "";
$i=0;
while ($i < $num) {
$name = mysql_result($result, $i, "fullname");
echo "";
echo "";
$i++;
}
答案 0 :(得分:2)
试
$sql = "SELECT
authorizations.customer_id,
accounts.fullname
FROM
authorizations
LEFT JOIN
accounts
ON
accounts.authorizing_person = authorizations.customer_id
WHERE
authorizations.agent_id = '$agentid'
ORDER BY
accounts.id DESC";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
echo "";
$i=0;
while ($i < $num) {
$name = mysql_result($result,$i,"fullname");
echo "";
echo "";
$i++;
}
答案 1 :(得分:1)
我不知道你的表的结构,但你可以遵循这个伪代码
SELECT name_of_person FROM accounts WHERE authorizing_person = (SELECT authorizing_person FROM authorization WHERE agent_id = '$agentid'"
答案 2 :(得分:0)
我明白了。只需使用customer_id而不是authorizing_customer。