0

フィルタ機能を作成しましたが、開始テーブルに問題があります。フィルタにカテゴリが選択されていない場合、テーブルから選択したすべてのデータを表示したいと思います。これまでのところ、カテゴリが選択された場合にのみ、必要なすべての必要なデータを表示できます。何も選択されていない場合は、空白のテーブルが表示されます。助けてください、...

これが関数です

 function listhistoryHost(){
    $accountid=$_SESSION['userid'];
    if(isset($_POST['button'])){

    $filter=$_POST['historyfilter'];

    if($filter==$filter){
    $sql="select * from webhostrequest where status='$filter' order by webhostrequest.recentact desc";
    $result=mysql_query($sql) or die("Error in selecting items ".mysql_error());
        $out="<ul>";
            while($row=mysql_fetch_array($result)){

                $accountid=$row['userid'];
                $requesttitle=$row['requesttitle'];
                $requestid=$row['requestid'];

                echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\">";
                echo "<tr class=\"rowcolor1\">";
                    echo "<td width=\"70%\"><span style=\"padding-left:20px\">Requested Web Hosting for  ".$row["requesttitle"]. "</td>";
                    echo "<td width=\"20%\"><span style=\"padding-left:20px\">Status: " .$row["status"]. "</td>";
                    echo "<td>
                    <center>
                        <form id = \"form1\" method = \"post\" action = \"viewhistorywebhost.php?webhost=$requestid\">
                            <input type = \"submit\" name = \"button\" id = \"button\" value = \"Details\" />
                        </form>
                    </center>";
                echo "</tr>";   
            }
            echo "</table>";
    return $out;
    }
    }
    }

フォームとトリガーは次のとおりです

 <form id = "form1" method = "post" action = "#">
        <select id="select1" name="historyfilter">
        <option value='' selected disabled>Select item type</option>
            <?php
                $options = array('approved' => 'Approved',
                                'cancelled'=>'Cancelled',
                                'rejected' => 'Rejected');
                foreach($options as $value => $type){
                    echo "<option value=\"$value\">$type</option>";
                }
            ?>
        </select>   
            <input type = "submit" name = "button" id = "submit" value = "Go" />
        </form>
    <?php
        $webhost=new requisition2();
        echo $webhost->listhistoryHost();
    ?>
4

2 に答える 2

0

空の$filterをチェックアウトする必要があります

if (empty($filter)) {
    $sql="select * from webhostrequest order by webhostrequest.recentact desc";
} else {
    $sql="select * from webhostrequest where status='$filter' order by webhostrequest.recentact desc";
}
于 2012-05-15T06:29:10.300 に答える
0

クエリのif条件を入力するだけです

function listhistoryHost(){
    $accountid=$_SESSION['userid'];
    if(isset($_POST['button'])){

    $filter=$_POST['historyfilter'];
    $sql="select * from webhostrequest order by webhostrequest.recentact desc";
    if(isset($filter))
       $sql="select * from webhostrequest where status='$filter' order by webhostrequest.recentact desc";

    $result=mysql_query($sql) or die("Error in selecting items ".mysql_error());
        $out="<ul>";
            while($row=mysql_fetch_array($result)){

                $accountid=$row['userid'];
                $requesttitle=$row['requesttitle'];
                $requestid=$row['requestid'];

                echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\">";
                echo "<tr class=\"rowcolor1\">";
                    echo "<td width=\"70%\"><span style=\"padding-left:20px\">Requested Web Hosting for  ".$row["requesttitle"]. "</td>";
                    echo "<td width=\"20%\"><span style=\"padding-left:20px\">Status: " .$row["status"]. "</td>";
                    echo "<td>
                    <center>
                        <form id = \"form1\" method = \"post\" action = \"viewhistorywebhost.php?webhost=$requestid\">
                            <input type = \"submit\" name = \"button\" id = \"button\" value = \"Details\" />
                        </form>
                    </center>";
                echo "</tr>";   
            }
            echo "</table>";
    return $out;
    }
}
于 2012-05-15T06:29:41.327 に答える