以下のスニペットをお試しください。理解していただければ幸いです。元のコードで
//check if properties is empty, if not, loop through them.
if(!empty($properties)):
foreach ($properties as $prop):
//check if $set_properties is empty, if not create select element
if(!empty($set_properties)):
//loop through properties, generate select element for current index
//obviously you can do proper select element naming and everything I just don't know your markup
//notice I do this after checking if the options fields are empty, so that way it only appears if there are options associated with it.
echo $prop->ID.": <select>";
//loop through set_properties, generate options
foreach ($set_properties as $set_prop):
echo "<option value='{$set_prop->ID}'>{$set_prop->Name}</option>";
endforeach;
//end select element, so next iteration will make a new one.
//again, inside the check for $set_properties because the select element will only exist if options exist
echo "</select>";
endif;
endforeach;
endif;
それはコードが乱雑になり、それは形式に難しくなってます、あなたは非常に多くの場合、PHPの中と外に切り替え、それが本当に必要ではありません。それに入るHTMLはあまりないので、PHPですべて書きましょう。変数を要素に挿入しようとしている場合や、HTMLがたくさんある場合は、PHPの入/出力を切り替えるだけです。
ここに記載されている内容は正しいですが、問題の内容を理解できません。 – GrumpyCrouton
だから、それぞれ11のオプションで6つのドロップダウンで終わるはずですか? – GrumpyCrouton
基本的にはyesです。 6つのドロップダウンとそれらのためのオプションがあります。私の例ではそれぞれ11個のオプションがありますが、後でこれらのオプションを分けていきます。したがって、dropdown 1には$ set_propertiesなどの特定のIDを持つ2つのオプションがあります。 –