【发布时间】:2021-06-23 14:23:34
【问题描述】:
我的查询按预期工作:
$sql = '
SELECT s.rowid
, f.fk_soc
, s.nom
, f.datef
, sc.fk_soc
, sc.fk_user
, u.rowid
, u.firstname
, u.lastname
FROM societe s
JOIN societe_commerciaux sc
ON s.rowid = sc.fk_soc
JOIN user u
ON sc.fk_user = u.rowid
LEFT
JOIN facture f
ON s.rowid = f.fk_soc
GROUP
BY s.rowid
HAVING MAX(f.datef) <= CURRENT_TIMESTAMP - INTERVAL '.$db->escape($dlo).' DAY
';
$resql = $db->query($sql);
if (!$resql) {
dol_print_error($db);
}
背景:
user - 包含用户名和姓的表以及主标识。 rowid
Societe - 带有客户名称 s.nom 主标识的表。 rowid
facture - 包含客户发票的表格,日期为 datef 和 fk_soc,这是客户 ID (s.rowid)
societe_commerciaux - 通过将fk_soc(实际上是 s.rowid)与 fk_user(即 u.rowid)匹配来建立代表每个客户端的用户的连接
工作脚本列出了在$dlo 和销售代表姓名设置的期间内没有发票的所有客户。
我想要做的是,调整结果以向没有发票的客户显示特定销售代表(即用户)。
我有一个工作脚本,填充下拉选择
<form>
<select name='repselect' onchange='showUser(this.value)'>
<option value="here comes the value for id of sales representative 1">Sales Representative name 1</option>
<option value="here comes the value for id of sales representative 2">Sales Representative name 2</option>
</select>
</form>
Value 字段中的 ID 是来自 table users 的 bot rowid 和来自 table societe_commerciaux 的 fk_ser。
我还有一个有效的 ajax 脚本来填充结果。
脚本的工作方式就像我在其中输入了print $sql;,在选择用户后我可以看到查询。
我正在苦苦挣扎的是如何调整上述查询以仅显示从下拉列表中选择的销售代表的结果。我将此 id 传递给一个文件“script.php”,其中有$userid = intval($_GET['q']);,后跟查询。我可以处理输出。这只是我无法正确调整的查询。
【问题讨论】:
-
如果
GROUP BY f.fk_soc , s.nom , f.datef , sc.fk_soc , sc.fk_user , u.rowid , u.firstname , u.lastname做的事情与GROUP BY s.rowid不同,那么事情会很糟糕。 -
按照建议,完成了这项工作。现在工作。在
JOIN societe_commerciaux sc ON s.rowid = sc.fk_soc之后添加 -
嗯?好吧,如果它有效,我与谁争论?
标签: php mysql sql ajax dropdown