1

列の名前を変数として PHP データベース クエリに渡そうとしています。

ハードコーディングされた構文は完全に機能し、次のとおりです。 select max([257612cr]) as price from Price_TekwaniPrice where customeraccount='DAY001'

変数を渡すと、エラーが発生しますtrying to get property ofnon object。私の構文は次のとおりです。

        $query = $this->db->query("
select max(['$product']) as price from Price where customeraccount='$customer'
      ");

私も試しました:

        $query = $this->db->query("
select max(".$product.") as price from Price where customeraccount='$customer'
      ");

変数が正しく渡されていることを確認しました。の構文は'$customer'完全に機能するため、変数を列名として渡すだけで$productは面倒です。

私はcodeigniterでphpを使用しています。どんなアドバイスも歓迎します。

いつもありがとう、

4

1 に答える 1