调用DB中的所有数据与选定的数据

时间:2014-02-02 09:14:55

标签: javascript php jquery mysql ajax

我有一个像这样的字母按钮(A,B ...... ALL),首先我点击它显示来自DB的所有数据,如果我按下A' A'如果我先点击“A'它非常快。下面是我的代码可以任何人指导我为什么它非常慢如果我按下A' A'按下ALL后。

if($client_id!=""){

$page = $_POST['page'];

$sql_selectsupplier  = "select * from supplierprice a JOIN $client_id b WHERE b.`net_id` = a.`supp_price_id` and country Like '$page%' ORDER BY `country` ASC";

print $sql_selectsupplier;

$result1 = mysql_query($sql_selectsupplier);

//print "query". $query;

while($rows=mysql_fetch_array($result1))
{

if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }

echo '   <td style="width:103px" class=" '.$rows["net_id"].'">'.$rows["clientid"].'</td>
         <td style="width:102px" id="CPH_GridView1_clientid" class=" '.$rows["net_id"].'">'.$rows["region"].'</td>  
        <td style="width:107px" id="CPH_GridView1_country" class=" '.$rows["net_id"].'">'.$rows["country"].'</td>
        <td style="width:184px" id="CPH_GridView1_networkname" class=" '.$rows["net_id"].'">'.$rows["networkname"].'</td>
        <td style="width:64px" id="CPH_GridView1_mcc"  class=" '.$rows["net_id"].'">'.$rows["mcc"].'</td>    
        <td style="width:65px"id="CPH_GridView1_mnc"  class="'.$rows["net_id"].'">'.$rows["mnc"].'</td>
        <td style="width:65px" id="CPH_GridView1_mnp" class="'.$rows["net_id"].'">'.$rows["mnp"].'</td>';
  /*                        
         $ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'supplierprice' AND column_name NOT
IN ('supp_price_id','net_id','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp'
)") or die("mysql error"); 

$columnArray=array();*/
 foreach($columnArray as $value) {

//$columnArray[]=$rows1[0];

echo '<td style="width:67px" id="CPH_GridView1_xxx" width="0px;" class="'.$value.' '.$rows["net_id"].'"><p>'.$rows[$value].'</p></td>';   
}   

 echo '<input type="hidden" name="myid" id="myid" value="CPH_GridView1_Status'.$rows['net_id'].'" class="text">';

 echo ' <td style="width:105px" id="CPH_GridView1_clientprice'.$rows['net_id'].'" class="edit clientprice '.$rows["net_id"].'">'.$rows["clientprice"].'</td>
        <td style="width:34px" id="CPH_GridView1_Status'.$rows['net_id'].'" class="edit2 status '.$rows["net_id"].' "><img  src="image/'.$rows["status"].'f.png" /></td>

        <td style="width:141px" > <select name="mySelect" id="mySelect" class="edit1 route '.$rows["net_id"].'" >         
           <option value="-1">Choose..</option>';
 $query = "SELECT route FROM routestable WHERE `clientid` = '$client_id' "; 

            $result = mysql_query($query);

            while ($rows1 = mysql_fetch_assoc($result))  
            {   
                    if(strlen($rows1['route'])>0 && $rows1['route']==$rows['route']){
    print' <option value="'.$rows1['route'].'" selected>'.$rows1['route'].' </option>';}

                else{

                echo '<option value="' . $rows1['route'] . '"> ' . $rows1['route'] .     '</option>';  

                }

            }   
        if($rows['seleniumrouteupdate']=="1")
            {

                $checked_value= "checked";
            }

            else{

                $checked_value="";
            }       

         echo '</select>
                            </td>


                     <td style="width:32px" id="CPH_GridView1_rollback'.$rows['net_id'].'" class="edit3 status1 '.$rows["net_id"].' "><img  src="image/refresh.png" style="cursor: pointer;" /></td>        


                        '
        ;

echo '</tr>';

}
  $msg = "<div class='pagination'><ul>";

    $msg .= "<li p='A' class='active'>A</li>";
    $msg .= "<li p='B' class='active'>B</li>";
    $msg .= "<li p='C' class='active'>C</li>";
    $msg .= "<li p='D' class='active'>D</li>";
    $msg .= "<li p='' class='active'>All</li>";

echo $msg;

}  

AJAX

<script type="text/javascript">
            $(document).ready(function(){
                $("#client").on("change", function() {

                var clientid=$("#client").val();

                function loading_show(){
                    $('#loading').html("<img src='image/loading.png'/>").fadeIn('fast');
                }
                function loading_hide(){
                    $('#loading').fadeOut('fast');
                }                
                function loadData(page){
                    loading_show();                    
                    $.ajax
                    ({
                        type: "POST",
                        url: "clientnetworkpricelist/quickyourfile.php",
                        data: "page="+page+"&clientid="+clientid,
                        success: function(msg)
                        {
                            $("#container").ajaxComplete(function(event, request, settings)
                            {
                                loading_hide();
                                $("#container").html(msg);
                            });
                        }
                    });
                }
                loadData(1);  // For first time page load default results
                $('#container .pagination li.active').live('click',function(){
                    var page = $(this).attr('p');
                    loadData(page);

                });           

                });
            });
        </script>

0 个答案:

没有答案