[Tep-j-general] Re: 複数の価格帯を持つ商品の検索

Back to archive index

Fujimoto-Kru2krungthep.com fujim****@kru2k*****
2005年 11月 4日 (金) 14:10:58 JST


はまださま

連絡が遅くなりました。
おかげさまで、ご指定の方法で問題が解決いたしました。

ありがとうございます。


藤本

----- Original Message ----- 
From: "hamada" <bungu****@leo*****>
To: <tep-j****@lists*****>
Sent: Monday, October 24, 2005 3:56 PM
Subject: [Tep-j-general] Re: 複数の価格帯を持つ商品の検索


>
> こんにちわ。
>
> On Mon, 24 Oct 2005 11:56:06 +0700
> "Fujimoto-Kru2krungthep.com" <fujim****@kru2k*****> wrote:
>
>> どうも基本的なところがよくわかっておらず、ご迷惑おかけいたします。
>
> そーゆー場合、基本に立ち戻るのが常道かと思います。
>
>> できれば通常の検索用の式をあまり変更せずに設定を変えたいのですが
>
> という意識が強すぎるためか、「いま有るものを小手先で弄る」ことに固執して、
> 投げる条件まで気が回らないってのは本末転倒も良いところ→自分が何をしたい
> のか、この際よく考えられるべきかと。
>
> SQLで特定のレコードを取り出したい場合、
>
> select 取り出したい値 from TABLE where 条件
>
> というSQLを投げます。で、advanced_search_result.phpは、大雑把に言ってこ
> の「条件」部を
>
> キーワード and カテゴリー and メーカーand 価格条件
>
> みたく生成してます。
>
> 今回いじるのは「価格条件」部だけなので、ここを詳細に見ます。
>
> 例として、計算が単純な「税無し価格」での条件生成部を見ます(税込でも基本
> 的な考え方は同じ。税計算されてるだけ)
>
>>     if ($pfrom) $where_str .= " and (IF(s.status, 
>> s.specials_new_products_price, p.products_price) >= " . $pfrom . ")";
>>     if ($pto)   $where_str .= " and (IF(s.status, 
>> s.specials_new_products_price, p.products_price) <= " . $pto . ")";
>
> $pfromが存在する場合>
>
> and (IF(s.status, s.specials_new_products_price, p.products_price) 
>  >=$pfrom)
>
> $ptoが存在する場合>
>
> and (IF(s.status, s.specials_new_products_price, p.products_price) <= 
> $pto)
>
> SQLのIFってのは
>
> http://dev.mysql.com/doc/refman/4.1/ja/control-flow-functions.html
>
>> IF(expr1,expr2,expr3)
>> expr1 が TRUE(expr1 <> 0 および expr1 <> NULL)の場合 IF() は expr2 を
>> 返し、それ以外の場合は expr3 を返す。
>
> なので、s.status=特価のフラグが立ってればs.specials_new_products_priceを、
> これが立ってなければp.products_priceを取り出すという指示→つまり、特価が
> 無い状況なら上記は
>
> and (p.products_price >= $pfrom)
> and (p.products_price <= $pto)
>
> と等価な訳です。ここまではお解り頂けたでしょか?
>
> 貴君の場合は
>
>> 当方ではp.products_priceとは別に
>> (マンション名)p.products_name
>> (30000円)pd.products_rents
>> (50000円)pd.products_rents2
>> (70000円)pd.products_rents3
>> (90000円)pd.products_rents4
>> (100000円)pd.products_rents5
>
> ↑こうらしいので、
>
> (pd.products_rents >= $pfrom and pd.products_rents <= $pto)
> or (pd.products_rents2 >= $pfrom and pd.products_rents2 <= $pto)
>
> とずらずらorで続けた全体を()で括り、これを「価格条件」としてandするべき
> じゃないんでしょか?
>
> となると後は、「$pfromがある場合」「$ptoが有る場合」をそれぞれif判定して
> SQLを作ってけば良いだけなんで
>
>> if ($pfrom || $pto) $where_str .= " and ((";
>> if ($pfrom) $where_str .= "pd.products_rents >= " . $pfrom;
>> if ($pfrom && $pto) $where_str .= " and ";
>> if ($pto) $where_str .= "pd.products_rents <= " . $pto;
>> if ($pfrom || $pto) $where_str .= ")";
>
> ↑こんな感じ?
>
> 少しでも読みやすくするためにすっげぇダサい書き方になってて自分でも涙出そ
> うです(^^;が、たぶんこれで目的に沿うハズ。
>
>> if ($pfrom || $pto) $where_str .= " or (";
>> if ($pfrom) $where_str .= "pd.products_rents2 >= " . $pfrom;
>> if ($pfrom && $pto) $where_str .= " and ";
>> if ($pto) $where_str .= "pd.products_rents2 <= " . $pto;
>> if ($pfrom || $pto) $where_str .= ")";
>
> あとは順次こんな風に足していって、最後
>
>> if ($pfrom || $pto) $where_str .= "))";
>
> で括れば、これで目的のSQLを生成できそうな気がします。
>
>
> はまだ@バックアップを忘れずに
> ------------------------------
> MLログ検索 http://www.bitscope.co.jp/search/tep.html
> osC-FAQ http://oscommerce.jouhou.tv/wiki/index.php?FAQ
>
> _______________________________________________
> Tep-j-general mailing list
> Tep-j****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/tep-j-general 





Tep-j-general メーリングリストの案内
Back to archive index