我非常接近让这个网站正常运行。在这个网站上的伟人的帮助下,我找到了最后一个问题的解决方案,并且还有最后一个问题。我的网站上有 8input
个字段,它们将根据选择的专业知识提取代理信息。如果数据库设置不同但我无法更改数据库的结构,这很可能会容易得多。
我的数据库结构:
ID | MemberID | First_Name | Last_Name | Ancillary | LongTerm | Medicare | ETC..<br />
1 | 77777 | John | Doe | 1 | 1 | 0 | ETC..
现在我需要根据用户选择的专业知识来提取信息。由于我的专业领域每个都是一列,并且它们的值是 1 表示是,0 表示否,因此对于新手程序员来说,这一定是让它变得更加复杂的原因。
用于根据选择的值进行拉取的 HTML:
<label for="agent">Agent Expertise</label><br />
<label for="ancillary"><input type="radio" value="Ancillary" onChange="showUser(this.value)" name="expertise[]" id="ancillary" />Ancillary</label><br />
<label for="smallgroup"><input type="radio" value="Smallgroup" onChange="showUser(this.value)" name="expertise[]" id="smallgroup" />Small Group</label><br />
<label for="largegroup"><input type="radio" value="LargeGroup" onChange="showUser(this.value)" name="expertise[]" id="largegroup" />Large Group</label><br />
<label for="medicare"><input type="radio" value="Medicare" onChange="showUser(this.value)" name="expertise[]" id="medicare" />Medicare</label><br />
<label for="longterm"><input type="radio" value="LongTerm" onChange="showUser(this.value)" name="expertise[]" id="longterm" />Long Term Care</label><br />
<label for="individual"><input type="radio" value="Individual" onChange="showUser(this.value)" name="expertise[]" id="individual" />Individual Plan</label><br />
<label for="tpa"><input type="radio" value="TPASelfInsured" onChange="showUser(this.value)" name="expertise[]" id="tpa" />TPA Self Insured</label><br />
<label for="ppaca"><input type="radio" value="CertifiedForPPACA" onChange="showUser(this.value)" name="expertise[]" id="ppaca" />Certified for PPACA</label><br />
jQuery 我曾经使用 ajax 拉取信息并发布到 div 中:
更新了我的 jQuery 和 AJAX
$(document).ready(function() {
$('input').on('click', function() {
var value = $(this).val();
$.ajax({
type: 'POST',
data: ({expertise: value}),
url: "expertise.php",
success: function (data) {
$('#bodyA').html(data);
}
});
});
})
现在sql是我遇到麻烦的地方:
$sql="SELECT * FROM `roster` WHERE Ancillary = '1' OR SmallGroup = '1' OR IndividualPlans = '1' OR LongTermCare = '1' OR Medicare = '1' OR LargeGroup = '1' OR TPASelfInsured = '1' OR CertifiedForPPACA = '1' ORDER BY Last_Name ASC";
当我使用 OR 时,它会调用数据库中的每个人,但当我使用 AND 时,它只会调用具有所有专业知识的代理。(对我来说很有意义)
PHP文件:
include 'datalogin.php'; // PHP File to login credentials
$sql="SELECT * FROM `roster` WHERE Ancillary = '1' OR SmallGroup = '1' OR IndividualPlans = '1' OR LongTermCare = '1' OR Medicare = '1' OR LargeGroup = '1' OR TPASelfInsured = '1' OR CertifiedForPPACA = '1' ORDER BY Last_Name ASC";
$result = mysqli_query($con,$sql) // Connects to database
or die("Error: ".mysqli_error($con));
echo "<h1>" . "Find a Local OAHU Agent." . "</h1>";
while ($row = mysqli_fetch_array($result)) { // Gets results from the database
echo "<div class='agentcon'>" . "<span class='agentn'>" . "<strong>".$row['First_Name'] . " " .$row['Last_Name'] . "</strong>" . "</span>" . "<a href=mailto:".$row['Email'] . ">" . "<span class='email'>" . "Send an e-mail to" . " " .$row['First_Name'] . "</span>" . "</a>" ."<div class='floathr'></div>";
if ($row['Company'] == NULL) {
echo "<p>";
}
else {
echo "<p>" . "<strong>" .$row['Company'] . "</strong>" . "<br>";
}
echo $row['WorkAddress1'] . " " .$row['WorkCity'] . "," . " " .$row['WorkStateProvince'] . " " .$row['WorkZipCode'] . "<br>";
if ($row['Work_Phone'] !== NULL) {
echo "<strong>" . "Work" . " " . "</strong>" .$row['Work_Phone'] . "<br>";
}
if ($row['Fax'] !== NULL) {
echo "<strong>" . "Fax" . " " . "</strong>" .$row['Fax'] . "<br>";
}
echo "<strong>" . "Agent Expertise:" . "</strong>";
if ($row['Ancillary'] == 1) {
echo " " . "Ancillary" . "/";
}
if ($row['SmallGroup'] == 1) {
echo " " . "Small Group" . "/";
}
if ($row['IndividualPlans'] == 1) {
echo " " . "Individual Plans" . "/";
}
if ($row['LongTermCare'] == 1) {
echo " " . "Long Term Care" . "/";
}
if ($row['Medicare'] == 1) {
echo " " . "Medicare" . "/";
}
if ($row['LargeGroup'] == 1) {
echo " " . "LargeGroup" . "/";
}
if ($row['TPASelfInsured'] == 1) {
echo " " . "TPA Self Insured" . "/";
}
if ($row['CertifiedForPPACA'] == 1) {
echo " " . "Certified For PPACA";
}
echo "</p>" . "</div>";
}
mysqli_close($con);