我有一个包含承包商和州的选择框。用户可以选择任意数量的承包商或州进行搜索。如何使用此多选框获取电子邮件地址?我的问题是他们可以选择多个承包商,多个州或根本没有州等等......
如何在所有这些条件下收到电子邮件?
选择框:
<select name="CID[]" id="CID[]" class="chosen-select" multiple="multiple">
<option value="All">All Active Contractors</option>
<?php foreach ($cq as $row): ?>
<option value="<?=$row['CID']?>"><?=$row['name']?></option>
<?php endforeach; ?>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
查询肥胖型:
$contractorquery = $db->prepare("SELECT CM.email, HO.name, HO.lastname, LL.state
FROM tbl_ContactMethods AS CM
JOIN tbl_HomeOwner AS HO ON HO.HID = CM.HID
JOIN tbl_Locations AS LL ON LL.HID=HO.HID
JOIN tbl_PressControl AS PC ON PC.HID = HO.HID
WHERE PC.CID = ??????? AND LL.state = ?????? AND PC.active = 1 AND CM.email IS NOT NULL");
$contractorquery->execute();
$cq = $contractorquery->fetchAll();
我有查询,如果他们选择&#34;全部&#34;因为我刚刚拿出了大部分的where子句:
SELECT CM.email, HO.name, HO.lastname
FROM tbl_ContactMethods AS CM
JOIN tbl_HomeOwner AS HO ON HO.HID = CM.HID
JOIN tbl_PressControl AS PC ON PC.HID = HO.HID
WHERE PC.active = 1 AND CM.email IS NOT NULL
答案 0 :(得分:0)
您必须使用IN(&#39; contratcor1&#39;,&#39;承包商2&#39;,&#39;等等ON&#39;)
$contractorquery = $db->prepare("SELECT CM.email, HO.name, HO.lastname, LL.state
FROM tbl_ContactMethods AS CM
JOIN tbl_HomeOwner AS HO ON HO.HID = CM.HID
JOIN tbl_Locations AS LL ON LL.HID=HO.HID
JOIN tbl_PressControl AS PC ON PC.HID = HO.HID
WHERE PC.CID IN('contratcor1','contractor2','and so ON') AND LL.state = ?????? AND
PC.active = 1 AND CM.email IS NOT NULL");