duanpei4455 2013-05-10 19:18
浏览 200
已采纳

分页不使用php和ajax工作

Below mentioned are 3 different files 1st file Package.php code:

<body>
    <form action='Add_Package.php' method='POST'>
    <input type='submit' id='btnAdd' value='Add Package Details'>

    <select id="pack_type" name="pack_type" onChange="package_changed()" >
    <option value="1">Valid</option>
    <option value="0">In-Valid</option>
    </select>
    <center><h1>Package Details</h1></center>
    <div id="package_info" name="package_info"> </div>
    <script type="text/javascript" src="js/service.js" ></script>
</body>

2nd File service.js code:

function package_changed()
{
    var xmlhttp;
    var type;
    type=document.getElementById("pack_type").value;
    if(type=="label")
    return;
    if(window.XMLHttpRequest)
    {
    xmlhttp=new XMLHttpRequest();
    }
    else
    {           
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {                   
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {                       
            document.getElementById("package_info").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","Package_description.php?type="+type,true);
    xmlhttp.send();         
}

3rd file Package_description.php code: $perpage=10;

    $row_count = mysql_query("select count(package_id) from package where is_valid=".$_GET['type']);
    $pages = ceil(mysql_result($row_count,0) / $perpage);   
    $page=(isset($_GET['page'])) ? (int)$_GET['page'] : 1;
    $start=($page - 1) * $perpage;

    $result = mysql_query("SELECT * FROM package where is_valid='".$_GET['type']."'ORDER BY package_id DESC LIMIT $start , $perpage ");

    echo '<div class="pagination pagination-middle pagination-right"><ul>';
    if($pages >= 1 && $page <=$pages)
    {
    for($x=1; $x<=$pages; $x++)
    {           
        if($x==$page)
    {
    echo '<li class="disabled"><a href="?page='.$x.'">'.$x.'</a></li>';
    }
    else
    {
    echo '<li class="active"><a href="?page='.$x.'">'.$x.'</a></li>';
    }                   
    }       
    }
    echo '</ul></div>';
    echo "  <center>                                
    <table class='table table-hover' border=5>
    <th>Package Name</th>
    <th>Package Credits</th>
    <th></th>";

    while($row=mysql_fetch_array($result))
    {
    echo "  <tr>                
    <td>" .$row['package_name'] ."</td>
    <td>" .$row['package_credits'] ."</td>
    <td><center><a href='Edit_Package.php?id=".$row['package_id'] . "'>Edit</a></center </td>
    </tr>";
    }
    echo "  </table><br>            
     </center>
     </form>";  
?>

Que: When I click on valid or invalid option in 1st file it will display the data properly. When the records are more than 10 then when I click on 2nd page It is not displaying the records from the 2nd page. The Problem is with javascript function because the same pagination script runs well when present on the same page here 3 different pages are involved including javascript function I don't know where exactly the problem is does any body have any solution please do let me know. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dqd72925 2013-05-11 05:03
    关注

    I actually found the solution for my problem Here are the changes what I did to my service.js file code:

    function package_changed()
    {
            var xmlhttp;
            var type;
            type=document.getElementById("pack_type").value;
            var url=document.URL;
            var thenum = url.replace( /^\D+/g, '');
    
            if(type=="label")
                return;
            if(window.XMLHttpRequest)
            {
                xmlhttp=new XMLHttpRequest();
            }
            else
            {           
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {                   
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {                       
            document.getElementById("package_info").innerHTML=xmlhttp.responseText;
            }
            }
            if(thenum=="")
            {
            xmlhttp.open("GET","Package_description.php?type="+type+"&page=1",true);
            xmlhttp.send(); 
            }
            else
            {
            xmlhttp.open("GET","Package_description.php?type="+type+"&page="+thenum,true);
            xmlhttp.send();         
            }
    }
    

    Actually I was not able to capture page variable and pass it onto package_description.php file so to that I captured package.php file url and stored into url variable and then I extracted only number part of it using .replace() function and some little bit changes as per the need hence done. Hope this thing might help someone in the future when similar problem arise. Any query then do comment. Thanks

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 angular项目错误
  • ¥20 需要帮我远程操控一下,运行一下我的那个代码,我觉得我无能为力了
  • ¥20 有偿:在ubuntu上安装arduino以及其常用库文件。
  • ¥15 请问用arcgis处理一些数据和图形,通常里面有一个根据点划泰森多边形的命令,直接划的弊端是只能执行一个完整的边界,但是我们有时候会用到需要在有很多边界内利用点来执行划泰森多边形的命令
  • ¥30 在wave2foam中执行setWaveField时遇到了如下的浮点异常问题,请问该如何解决呢?