過去数日間、これを解決しようとしましたが、成功しませんでした。私が基本的に持っているのは、ユーザーの写真を保存できる4つのデータベースフィールドで、ユーザーは最大4つの写真を持つことができます。フィールド名は、picture1、picture2、picture3、picture4 です。私がやろうとしているのは、ユーザーが写真をアップロードするとき、picture1 が NULL かどうかを確認し、そうでない場合はそこに画像ファイル名を保存し、NULL でない場合は次の写真のために picture2 に移動し、picture4 まで保存することです。
持っているものはこれです:
if (openhouse.picture1 == null)
{
openhouse.picture1 = changename;
}
// if picture2 is NULL and picture1 is not NULL then insert picture
if (openhouse.picture2 == null && openhouse.picture1 != null)
{
openhouse.picture2 = changename;
}
// if picture3 is NULL and picture2 is not NULL then insert picture
if (openhouse.picture3 == null && openhouse.picture2 != null)
{
openhouse.picture3 = changename;
}
// if picture4 is NULL and picture3 is not NULL then insert picture
if (openhouse.picture4 == null && openhouse.picture3 != null)
{
openhouse.picture4 = changename;
}
ご覧のとおり、私の問題は、写真をアップロードするとすぐに、 IF ステートメントに区切りがないため、同じ写真が4 つのフィールドすべてにアップロードされることです。私の質問は、この if ステートメントを switch ステートメントに転送できる方法はありますか条件が真になるとすぐにBREAKSをそのように使用し、残りの評価を停止します。