0

私はこのウェブサイトが正しく機能することに非常に近づいています. このサイトの素晴らしい人たちの助けを借りて、最後の質問に対する解決策を見つけました。最後の質問が 1 つあります。input私のサイトには、選択された専門知識に基づいてエージェント情報を取得する8 つのフィールドがあります。データベースが別の方法で設定されている場合、これはおそらくはるかに簡単ですが、データベースの構造を変更することはできません。

サイトのライブバージョン

私のデータベース構造:

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 を使用すると、すべての専門知識を持つエージェントのみが呼び出されます。(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);
4

1 に答える 1

2

私は注射予防の専門家ではありませんが、あなたの専門知識をこのように内破することはできませんでした.

JQuery:

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

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>

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;
    }
}

}

これはすべて、私のサーバーで問題なくテストされました。

于 2013-08-02T23:03:25.810 に答える