2011-01-19 4 views
1

新しいアイテムがデータベースに追加されたときに送信される電子メール通知システムを作成しようとしています。これらのすべては、ドロップダウンリストであるジョブアラートに似た電子メール通知を送信するための少しのヘルプ

Color [n/a, pink, red, blue, and green] 
Shape [n/a, square, rectangle, and circle] 
width [n/a, narrow, wide] 

-

ユーザーが自分のメールアドレスを提供することにより、および以下のようにしている自分の好みを選択して登録します。

したがって、ユーザーが色を赤色として選択し、他のすべてのオプションをn/aとしておくと、赤色の色を持つ新しい項目の通知を受け取りたいということです。 Colore = redとShape = circleを選択すると、赤の赤いANDシェイプを持つアイテムだけの通知が円として表示されます。

項目テーブル

id, color, shape, width, height, name, description, image 

サンプル列

1, red, circle, narrow, tall, ABC, ABC Descrip, yellowFlag.jpg 
2, blue, circle, wide, short, XYZ, XYZ Descrip, redFlag.jpg 

通知表

id, email, color, shape, width 

サンプル列

1, [email protected], red, 0, 0, 0 
2, [email protected], blue, circle, 0 
3, [email protected], pink, square, wide 

選択はいずれかの選択を選ぶことができます。 私はDBへ(項目テーブルの上の)数2項目を追加した場合、私は通知に一致しているユーザーに通知を送信したい - 例えば、以下を参照してください、彼らは

color = red, shape = 0, width = 0 [0 is n/a, selected red only] 
color = 0, shape = square, width= 0 [selected shape only] 
color = 0, shape = 0, width= 'narrow' [selected width only] 
color = red, shape = square, width= 0 [selected both color and shape but not width] 
color = 0, shape = square, width= 'narrow' [selected both shape and width but not color] 
color = red, shape = square, width= narrow [selected all 3 options] 
color = red, shape = 0, width= narrow [selected color and width but not shape] 

私の質問がありを選択することができます表。私は考えることができるの通知表を照会する唯一の方法は、

1. SELECT email FROM notifications WHERE color = 'blue', shape = '0', '0' 
2. SELECT email FROM notifications WHERE color = 'blue', shape = 'circle', '0' 
3. SELECT email FROM notifications WHERE color = 'blue', shape = 'circle', 'wide' 
4. SELECT email FROM notifications WHERE color = '0', shape = '0', 'wide' 
5. SELECT email FROM notifications WHERE color = 'blue', shape = 'circle', '0' 
6. SELECT email FROM notifications WHERE color = 'blue', shape = 'circle', 'wide' 

ようなものです...ので、

にそれは非効率的な方法です。また、現在のオプションの数は3(色、形、幅)ですが、別のオプションをいくつか追加しなければならない場合、すべてが狂ってしまいます(一緒に)。これを達成するには、求人アラートのような多くのアプリケーションがすでに存在するため、これを達成するにはより良い方法が必要です。これらを管理するためのより優れた方法やアイデアを教えてください。私はテーブルなどの構造を変更することに問題がないので、任意のアイデアを歓迎しています。ご不明な点がございましたら、お尋ねください。私はあなたの助けに感謝します。

ありがとうございます。

答えて

0

私は、与えられたユーザーのすべての嗜好を収集し、テーブルを持っていると思います:

表の基準:

id: some ID for the criteria 
label: human readable description of the criteria 
column: name of the corresponding column in the notification table 
values: optional comma-separated list of possible values 

表は青を持つユーザーを見つけること

id: some id for the preference 
user_id: the user 
criteria_id: the criteria 
value: the chosen value for the criteria 

をuser_preferences色および正方形の好み:

SELECT u.id, u.email 
FROM user u, criteria c, user_preferences up 
WHERE 
     up.id = u.id 
    AND c.id = up.criteria_id 
    AND c.column = 'shape' 
    AND up.value='square' 

INTERSECT 

SELECT u.id, u.email 
FROM user u, criteria c, user_preferences up 
WHERE 
     up.id = u.id 
    AND c.id = up.criteria_id 
    AND c.column = 'color' 
    AND up.value='blue' 

そして、あなたはアイテムを追加するとき、あなたは青色または正方形の嗜好を持つユーザーを見つけることになるでしょう:

SELECT u.id, u.email 
FROM user u, criteria c, user_preferences up 
WHERE 
     up.id = u.id 
    AND c.id = up.criteria_id 
    AND ((c.column = 'shape' AND up.value='square') 
    OR (c.column = 'color' AND up.value='blue') 
) 
+0

あらかじめ作成された基準のリストを作成して、ユーザが選択できるようにしましたか? – Kay

+0

あなたの質問をもう一度お読みになり、質問の条件に従うように通知するだけでユーザーを置き換えてください。そして、はい、制限値のリストを持っていて、ユーザーがそれらの1つ以上を選択できるようにします。テストされたものは何もありませんが、あなたの通知システムにしっかりとした/拡張可能なベースを与えるべきです。 –

+0

また、アイテムテーブルによって基準が再利用される可能性があります。これにより、通知プロセスをさらに自動化することさえできます –

0

アイテムテーブルに行を挿入した場合意味、色=赤、形状値= 0、width = 0 .............

通知テーブルから、特定の一致する値のカラーID、色=赤、形状= 0、幅= 0のメールIDを選択します。

am i correct ????

プロセスページに移動します。つまり、クエリページを挿入します。この投稿データを使用してそこからデータを選択します。例えば

$color=$_POST['color']; 
$shape=$_POST['shape']; 
$width=$_POST['width']; 

その後、私はこれがあなたのニーズであると思います選択クエリ

"select email from notifications where color='$color' and shape='$shape' and width='$width'" 

を使う......

が、通知表にない問題 のthatsまた、値0を使用します。

ユーザが赤のみを選択した場合、あなたのinsertioあなたのニーズを確実にしてくれるように、 のように色を入力してください。

+0

そうですね。新しい項目がデータベースに追加されると、ITEMテーブルの値と一致するリクエストがあるユーザーが存在するかどうかを確認する必要があります。 – Kay

+0

ユーザーがcolor = redを選択した場合、これは、シェイプと幅に関係なく赤色を持つアイテムの通知を受け取ることを意味します。この場合、上記は役に立たないでしょう。 :( – Kay

関連する問題