0

可変句を使用して繰り返し発生するSQL選択をコーディングしています。句には、PHP 変数があります (後で WHILE.

私のコード:

$custaccount_id_clause = "(SELECT DISTINCT(custaccount_id) AS custaccount_id FROM accountcomms_def_tbl a WHERE subagent_def_id = " . '\'$interest_id\'' . " AND agentorder > (SELECT agentorder FROM accountcomms_def_tbl WHERE subagent_def_id = '$subagent_def_id' and custaccount_id = a.custaccount_id))";

$subagent_def_id は、すでに定義されているため機能します。

$interest_id は定義されていないため機能しません。while ループの一部として $custaccount_id_clause を呼び出している while ループ中に、後で $interest_id に置き換えようとしています。

    $allresidual_sql = mysql_query("SELECT SUM(txn_value) as txn_sum, COUNT(DISTINCT(custaccount_id)) AS accounts FROM account_stmnt_tbl WHERE txn_type IN ('Fixed Residual','Variable Residual','One Time Adjustment') AND custaccount_id IN ". $custaccount_id_clause)or die(mysql_error());
  1. $custaccout_id 句内に、PHP で変数を置き換えたいテキスト '$interest_id' があります。変数を置き換えていません。

  2. これは私がデモ用に書いている簡単なサンプルアプリです。私が使用している API について私に説明しないでください。本番環境に入るコードを書くつもりはありません! :)

4

1 に答える 1