Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用mysql从单击复选框/单选按钮的8列中抽取1列_Php_Mysql - Fatal编程技术网

Php 使用mysql从单击复选框/单选按钮的8列中抽取1列

Php 使用mysql从单击复选框/单选按钮的8列中抽取1列,php,mysql,Php,Mysql,我很快就能让这个网站正常运行了。在这个网站上的伟大人物的帮助下,我找到了最后一个问题的解决方案,我还有最后一个问题。我的网站上有8个input字段,可以根据选择的专业知识获取代理信息。如果数据库的设置不同,这可能会容易得多,但我不能更改数据库的结构 我的数据库结构: ID | MemberID | First_Name | Last_Name | Ancillary | LongTerm | Medicare | ETC..<br /> 1 | 77777 | John

我很快就能让这个网站正常运行了。在这个网站上的伟大人物的帮助下,我找到了最后一个问题的解决方案,我还有最后一个问题。我的网站上有8个
input
字段,可以根据选择的专业知识获取代理信息。如果数据库的设置不同,这可能会容易得多,但我不能更改数据库的结构

我的数据库结构:

ID | MemberID | First_Name | Last_Name | Ancillary | LongTerm | Medicare |  ETC..<br />
 1 | 77777    | John       | Doe       | 1         | 1        | 0        | ETC..
现在,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'] . "&nbsp;" .$row['Last_Name'] . "</strong>" . "</span>" . "<a href=mailto:".$row['Email'] . ">" . "<span class='email'>" . "Send an e-mail to" . "&nbsp;" .$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'] . "&nbsp;" .$row['WorkCity'] . "," . "&nbsp;" .$row['WorkStateProvince'] . "&nbsp;" .$row['WorkZipCode'] . "<br>";
                if ($row['Work_Phone'] !== NULL) {
                    echo "<strong>" . "Work" . "&nbsp;" . "</strong>" .$row['Work_Phone'] . "<br>";
                }
                if ($row['Fax'] !== NULL) {
                    echo "<strong>" . "Fax" . "&nbsp;" . "</strong>" .$row['Fax'] . "<br>";
                }
                echo "<strong>" . "Agent Expertise:" . "</strong>";
                if ($row['Ancillary'] == 1) {
                    echo "&nbsp;" . "Ancillary" . "/";
                }
                if ($row['SmallGroup'] == 1) {
                    echo "&nbsp;" . "Small Group" . "/";
                }
                if ($row['IndividualPlans'] == 1) {
                    echo "&nbsp;" . "Individual Plans" . "/";
                }
                if ($row['LongTermCare'] == 1) {
                    echo "&nbsp;" . "Long Term Care" . "/";
                }
                if ($row['Medicare'] == 1) {
                    echo "&nbsp;" . "Medicare" . "/";
                }
                if ($row['LargeGroup'] == 1) {
                    echo "&nbsp;" . "LargeGroup" . "/";
                }
                if ($row['TPASelfInsured'] == 1) {
                    echo "&nbsp;" . "TPA Self Insured" . "/";
                }
                if ($row['CertifiedForPPACA'] == 1) {
                    echo "&nbsp;" . "Certified For PPACA";
                }
                echo "</p>" . "</div>";
            }

        mysqli_close($con);
包括“datalogin.php”;//登录凭证的PHP文件
$sql=“从`花名册'中选择*,其中辅助='1'或小团体='1'或个人计划='1'或长期护理='1'或医疗保险='1'或大团体='1'或TpaSelfInsurance='1'或CertifiedForPPACA='1'按姓氏ASC订购”;
$result=mysqli\u query($con,$sql)//连接到数据库
或者死(“错误:.mysqli_错误($con));
“回声”。“找一个当地瓦胡岛的特工。”。"";
而($row=mysqli\u fetch\u array($result)){//从数据库获取结果
回显“.”。“$row['First\u Name']”。.$row['Last\u Name']”。”;
如果($row['Company']==NULL){
回声“”;
}
否则{
回声“”“$row['Company']”。
”; } 回显$row['WorkAddress1']。“..row['WorkCity']。”,“..row['WorkStateProvince']。”。“$row['WorkZipCode']。”
”; 如果($row['Work\u Phone']!==NULL){ 回声“”“工作”。“”$row['Work\u Phone']。“
”; } 如果($row['Fax']!==NULL){ 回声“”“传真”。“”$row['Fax']。“
”; } echo“”代理专业知识:“”; 如果($row['associative']==1){ 回声“.”辅助“/”; } 如果($row['SmallGroup']==1){ 回声“.”“小团体“/”; } 如果($row['IndividualPlans']==1){ 回显“.”“个别计划”。/“; } if($row['LongTermCare']==1){ echo.“长期护理”。/”; } 如果($row['Medicare']==1){ echo.““医疗保险”。/”; } 如果($row['LargeGroup']==1){ 回显“.”“大组“/”; } 如果($row['TpaSelf-insurated']==1){ echo.““TPA自保”。/”; } 如果($row['CertifiedForpAca']==1){ echo.“通过PPACA认证”; } 回声“

”; } mysqli_close($con);
我不是注射预防方面的专家,但你不能像这样内化你的专业知识

JQuery:

<script>
    function showUser(){
    $.post("expertise.php",$('#expertiseform').serialize(), function(data){$('#bodyA').html(data)});
return false;
}
</script>

函数showUser(){
$.post(“experties.php”,$('#expertiseform').serialize(),函数(数据){$('#bodyA').html(数据)});
返回false;
}
HTML:

      <form id="expertiseform" action="expertise.php" method="POST">
           <label for="agent">Agent Expertise</label><br />
           <label for="ancillary"><input type="checkbox" value="Ancillary" onClick="showUser(this)" name="expertise[]" id="ancillary" />Ancillary</label><br />
           <label for="smallgroup"><input type="checkbox" value="Smallgroup" onClick="showUser(this)" name="expertise[]" id="smallgroup" />Small Group</label><br />
           <label for="largegroup"><input type="checkbox" value="LargeGroup" onClick="showUser(this)" name="expertise[]" id="largegroup" />Large Group</label><br />
           <label for="medicare"><input type="checkbox" value="Medicare" onClick="showUser(this)" name="expertise[]" id="medicare" />Medicare</label><br />
           <label for="longterm"><input type="checkbox" value="LongTerm" onClick="showUser(this)" name="expertise[]" id="longterm" />Long Term Care</label><br />
           <label for="individual"><input type="checkbox" value="Individual" onClick="showUser(this)" name="expertise[]" id="individual" />Individual Plan</label><br />
           <label for="tpa"><input type="checkbox" value="TPASelfInsured" onClick="showUser(this)" name="expertise[]" id="tpa" />TPA Self Insured</label><br />
           <label for="ppaca"><input type="checkbox" value="CertifiedForPPACA" onClick="showUser(this)" name="expertise[]" id="ppaca" />Certified for PPACA</label><br />
      </form>

代理专业知识
辅助的
小团体
大群体
医疗保险
长期护理
个人计划
TPA自保
通过PPACA认证
PHP:

    $poststr = $_POST['expertise']; //get our post data
if(is_array($poststr)){
if(count($poststr) > 1){ //count to make sure we have an array
    $expertise = implode(" AND ",$_POST['expertise']); //implode the array using AND as glue
}else{              //otherwise implode without glue
    $expertise = implode("",$poststr);
}
//here is our string for prepared statement
$sql = "SELECT First_Name, Last_Name, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA FROM roster WHERE ".$expertise." = 1";

if(!$stmt = $con->Prepare($sql))
{ 
    die; //echo error info if you want to know info

}else{
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($First_Name, $Last_Name, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA);
    $rows = $stmt->num_rows;
    if($rows >0){
        echo "<h1>" . "Find a Local OAHU Agent." . "</h1>";
            while ($stmt->fetch()) { // Gets results from the database
            echo "<div class='agentcon'>" . "<span class='agentn'>" . "<strong>".$First_Name . "&nbsp;" .$Last_Name . "</strong>" . "</span>" . "<a href=mailto:".$Email . ">" . "<span class='email'>" . "Send an e-mail to" . "&nbsp;" .$First_Name . "</span>" . "</a>" ."<div class='floathr'></div>";
            if ($Company == NULL) {
                echo "<p>";
            }
            else {
                echo "<p>" . "<strong>" .$Company . "</strong>" . "<br>";
            }
            echo $WorkAddress1 . "&nbsp;" .$WorkCity . "," . "&nbsp;" .$WorkStateProvince . "&nbsp;" .$WorkZipCode . "<br>";
            if ($Work_Phone !== NULL) {
                echo "<strong>" . "Work" . "&nbsp;" . "</strong>" .$Work_Phone . "<br>";
            }
            if ($Fax !== NULL) {
                echo "<strong>" . "Fax" . "&nbsp;" . "</strong>" .$Fax . "<br>";
            }
                echo "<strong>" . "Agent Expertise:" . "</strong>";
            if ($Ancillary == 1) {
                echo "&nbsp;" . "Ancillary" . "/";
            }
            if ($SmallGroup == 1) {
                echo "&nbsp;" . "Small Group" . "/";
            }
            if ($IndividualPlans == 1) {
                echo "&nbsp;" . "Individual Plans" . "/";
            }
            if ($LongTermCare == 1) {
                echo "&nbsp;" . "Long Term Care" . "/";
            }
            if ($Medicare == 1) {
                echo "&nbsp;" . "Medicare" . "/";
            }
            if ($LargeGroup == 1) {
                echo "&nbsp;" . "LargeGroup" . "/";
            }
            if ($TPASelfInsured == 1) {
                echo "&nbsp;" . "TPA Self Insured" . "/";
            }
            if ($CertifiedForPPACA == 1) {
                echo "&nbsp;" . "Certified For PPACA";
            }
            echo "</p>" . "</div>";
        }
    $stmt->close;
    }else{
        Die;
    }
}
$poststr=$\u POST['experties']//获取我们的帖子数据
if(is_数组($poststr)){
如果(count($poststr)>1{//count以确保我们有一个数组
$experties=内爆(“AND”,$\u POST['experties']);//使用和作为粘合剂内爆数组
}否则{//否则在没有胶水的情况下内爆
$experties=内爆(“,$poststr”);
}
//这是我们准备好的语句的字符串
$sql=“从花名册中选择姓名、姓氏、电子邮件、公司、工作地址1、工作城市、工作状态省、工作密码、工作电话、传真、辅助、小团体、个人计划、长期护理、医疗保险、大团体、Tpaself-insurance、CertifiedForPPACA,其中“$Experties.”=1”;
如果(!$stmt=$con->Prepare($sql))
{ 
die;//如果您想知道错误信息,请返回错误信息
}否则{
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($First_Name、$Last_Name、$Email、$Company、$WorkAddress1、$WorkCity、$WorkStateProvince、$WorkZipCode、$Work_Phone、$Fax、$associative、$SmallGroup、$individualplan、$LongTermCare、$Medicare、$LargeGroup、$tpa自保、$CertifiedForPPACA);
$rows=$stmt->num\u行;
如果($rows>0){
echo.“查找本地瓦胡岛代理”;
而($stmt->fetch()){//从数据库获取结果
回声“.”。“$First\u Name.”“$Last\u Name.”“.”;
如果($Company==NULL){
回声“”;
}
否则{
回声“”“$Company.”
”; } echo$WorkAddress1.“$WorkCity.”、“$WorkStateProvince.”、“$WorkZipCode.”等; 如果($Work\u Phone!==NULL){ 回声“”“工作”。“”$Work\u电话。”
”; } 如果($Fax!==NULL){ 回显“”“传真”。“$Fax。”
”; } echo“”代理专业知识:“”; 如果($辅助==1){ 回声“.”辅助“/”; } 如果($SmallGroup==1){ 回声“.”“小团体“/”;
      <form id="expertiseform" action="expertise.php" method="POST">
           <label for="agent">Agent Expertise</label><br />
           <label for="ancillary"><input type="checkbox" value="Ancillary" onClick="showUser(this)" name="expertise[]" id="ancillary" />Ancillary</label><br />
           <label for="smallgroup"><input type="checkbox" value="Smallgroup" onClick="showUser(this)" name="expertise[]" id="smallgroup" />Small Group</label><br />
           <label for="largegroup"><input type="checkbox" value="LargeGroup" onClick="showUser(this)" name="expertise[]" id="largegroup" />Large Group</label><br />
           <label for="medicare"><input type="checkbox" value="Medicare" onClick="showUser(this)" name="expertise[]" id="medicare" />Medicare</label><br />
           <label for="longterm"><input type="checkbox" value="LongTerm" onClick="showUser(this)" name="expertise[]" id="longterm" />Long Term Care</label><br />
           <label for="individual"><input type="checkbox" value="Individual" onClick="showUser(this)" name="expertise[]" id="individual" />Individual Plan</label><br />
           <label for="tpa"><input type="checkbox" value="TPASelfInsured" onClick="showUser(this)" name="expertise[]" id="tpa" />TPA Self Insured</label><br />
           <label for="ppaca"><input type="checkbox" value="CertifiedForPPACA" onClick="showUser(this)" name="expertise[]" id="ppaca" />Certified for PPACA</label><br />
      </form>
    $poststr = $_POST['expertise']; //get our post data
if(is_array($poststr)){
if(count($poststr) > 1){ //count to make sure we have an array
    $expertise = implode(" AND ",$_POST['expertise']); //implode the array using AND as glue
}else{              //otherwise implode without glue
    $expertise = implode("",$poststr);
}
//here is our string for prepared statement
$sql = "SELECT First_Name, Last_Name, Email, Company, WorkAddress1, WorkCity, WorkStateProvince, WorkZipCode, Work_Phone, Fax, Ancillary, SmallGroup, IndividualPlans, LongTermCare, Medicare, LargeGroup, TPASelfInsured, CertifiedForPPACA FROM roster WHERE ".$expertise." = 1";

if(!$stmt = $con->Prepare($sql))
{ 
    die; //echo error info if you want to know info

}else{
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($First_Name, $Last_Name, $Email, $Company, $WorkAddress1, $WorkCity, $WorkStateProvince, $WorkZipCode, $Work_Phone, $Fax, $Ancillary, $SmallGroup, $IndividualPlans, $LongTermCare, $Medicare, $LargeGroup, $TPASelfInsured, $CertifiedForPPACA);
    $rows = $stmt->num_rows;
    if($rows >0){
        echo "<h1>" . "Find a Local OAHU Agent." . "</h1>";
            while ($stmt->fetch()) { // Gets results from the database
            echo "<div class='agentcon'>" . "<span class='agentn'>" . "<strong>".$First_Name . "&nbsp;" .$Last_Name . "</strong>" . "</span>" . "<a href=mailto:".$Email . ">" . "<span class='email'>" . "Send an e-mail to" . "&nbsp;" .$First_Name . "</span>" . "</a>" ."<div class='floathr'></div>";
            if ($Company == NULL) {
                echo "<p>";
            }
            else {
                echo "<p>" . "<strong>" .$Company . "</strong>" . "<br>";
            }
            echo $WorkAddress1 . "&nbsp;" .$WorkCity . "," . "&nbsp;" .$WorkStateProvince . "&nbsp;" .$WorkZipCode . "<br>";
            if ($Work_Phone !== NULL) {
                echo "<strong>" . "Work" . "&nbsp;" . "</strong>" .$Work_Phone . "<br>";
            }
            if ($Fax !== NULL) {
                echo "<strong>" . "Fax" . "&nbsp;" . "</strong>" .$Fax . "<br>";
            }
                echo "<strong>" . "Agent Expertise:" . "</strong>";
            if ($Ancillary == 1) {
                echo "&nbsp;" . "Ancillary" . "/";
            }
            if ($SmallGroup == 1) {
                echo "&nbsp;" . "Small Group" . "/";
            }
            if ($IndividualPlans == 1) {
                echo "&nbsp;" . "Individual Plans" . "/";
            }
            if ($LongTermCare == 1) {
                echo "&nbsp;" . "Long Term Care" . "/";
            }
            if ($Medicare == 1) {
                echo "&nbsp;" . "Medicare" . "/";
            }
            if ($LargeGroup == 1) {
                echo "&nbsp;" . "LargeGroup" . "/";
            }
            if ($TPASelfInsured == 1) {
                echo "&nbsp;" . "TPA Self Insured" . "/";
            }
            if ($CertifiedForPPACA == 1) {
                echo "&nbsp;" . "Certified For PPACA";
            }
            echo "</p>" . "</div>";
        }
    $stmt->close;
    }else{
        Die;
    }
}