get 多值的寫法


<?php require_once("config.php");?>//開頭的載入


<?php
if(isset($_GET['now_Page'])){
  $now_Page=$_GET['now_Page'];
}else{
  $now_Page=1;
}

$sort_id = $_GET['sort_id'];
  if($_GET['sort_id']){$sort = "?sort_id=".$_GET['sort_id'];}
  $s_index = $s_index.$sort; //其實不需,因為config檔裡就有命名


//換頁語法

      <?php

    $where = " where sort_id=".$sort_id." order by seq";

         $sql="select count(*) from ".$s_table.$where ;
    
    $pageShower=pageCreater($now_Page,10,$sql,$cn,$s_index,"");

        $sql="select * from ".$s_table.$where. " limit ".$record_begin.",".$record_show;

        $result=mysql_query($sql,$cn);
        
        echo $pageShower;
        ?>


$getpart = getparent($sort_id,$cn);


但是一直換頁有問題

config檔
<?php

    $s_title     = "下載中心";
    $s_table     = "dynamic";            //查詢的表格
    $s_index     = "index.php";        //設置返回的頁面
    $s_edit     = "edit.php";        //編輯頁面
    $s_update     = "update.php";        //更新頁面

    $s_upload    = "../../uploads/";    //文件上傳路徑
    $s_uptype    = "jpg,jpge,png,gif";    //上傳文件類型




function getparent($sort_id,$cn){
  $sql = "select * from dynamic_sort where id=".$sort_id;
  $result = mysql_query($sql,$cn);
  $rs=mysql_fetch_array($result);

  $sql1 = "select * from dynamic_sort where id=".$rs['parentid'];
  $result1 = mysql_query($sql1,$cn);
  $rs1=mysql_fetch_array($result1);  

  $getpart['sortname'] = $rs['sortname'];
  $getpart['parentname'] = $rs1['sortname'];
  $getpart['parentid'] = $rs1['id'];
  return $getpart; 
}    
?>

   

以及pageCreater檔
<?php
//換頁API
    function pageCreater($now_Page,$show_num,$sql,$cn,$pageName,$pageValue){
    //$pageValue 而外參數
    //秀出的筆數
    //$show_num = 2;
    
    //宣告全域變數
    global $record_begin,$record_show;
    
    // 本頁之起始指標    
    $record_begin = ($now_Page-1) * $show_num;

    // 本頁實際顯示筆數    
    $record_show  = $show_num;

    // 計算總筆數
    //$sql="select count(*) from member";
    $result=mysql_query($sql,$cn);
    list($nTotal)=mysql_fetch_array($result);//list() 把陣列長度變成數值    
    
    
    // 本頁之實際顯示筆數不可大於總筆數
    if (( $record_begin + $record_show ) > $nTotal ){
          $record_show = $nTotal - $record_begin;
    }

    //求總頁數
    if(($nTotal%$show_num)==0){
        $totalPage=$nTotal/$show_num;
    }else{
        $totalPage=intval($nTotal/$show_num)+1;    
    }
//跳頁數
    $pageJumper="<select id='pageJumber' >";

    for($i=1;$i<=$totalPage;$i++){

        if($i==$now_Page){
            $pageJumperAnchor="selected='selected'";
        }else{
            $pageJumperAnchor="";
        }
    
        $pageJumper.="<option value='".$i."' ".$pageJumperAnchor.">".$i."</option>";

    }

    $pageJumper.="</select>";
    //總頁數
    $pageCounter="&lt;".$now_Page."/".$totalPage."&gt;";
    //第一頁&上一頁
    if($now_Page>1){
        $firstPage="<a href='".$pageName."?now_Page=1".$pageValue."'>第一頁</a>";
        $prePage="<a href='".$pageName."?now_Page=".($now_Page-1).$pageValue."'>上一頁</a>";    
    }else{
        $firstPage="<a href='javascript:void(0)'>第一頁</a>";
        $prePage="<a href='javascript:void(0)'>上一頁</a>";
    }
    //下一頁&最終頁
    if($now_Page<$totalPage){
        $nextPage="<a href='".$pageName."?now_Page=".($now_Page+1).$pageValue."'>下一頁</a>";
        $lastPage="<a href='".$pageName."?now_Page=".$totalPage.$pageValue."'>最後一頁</a>";    
    }else{
        $nextPage="<a href='javascript:void(0)'>下一頁</a>";
        $lastPage="<a href='javascript:void(0)'>最後一頁</a>";
    }

    $pageShower="<ul class='pageShower'><li>".$firstPage."</li><li>".$prePage."</li><li>".$nextPage."</li><li>".$lastPage."</li><li>".$pageCounter."</li></ul>";

    //<li>".$pageJumper."</li>
    return $pageShower;    
}

?>
    
改成這樣解決了問題
<?php
if(isset($_GET['now_Page'])){
  $now_Page=$_GET['now_Page'];
}else{
  $now_Page=1;
}

$sort_id = $_GET['sort_id'];
  if($_GET['sort_id']){$sort = "?sort_id=".$_GET['sort_id'];}

  $idx = $s_index; //把index重設
  $s_index = $s_index.$sort; //多餘的命名


$getpart = getparent($sort_id,$cn);

?>

<?php

    $where = " where sort_id=".$sort_id." order by seq";

         $sql="select count(*) from ".$s_table.$where ;
    $pageShower=pageCreater($now_Page,10,$sql,$cn,$idx,"&sort_id=".$_GET['sort_id']);

        $sql="select * from ".$s_table.$where. " limit ".$record_begin.",".$record_show;
        $result=mysql_query($sql,$cn);
        
        echo $pageShower;
        ?>

只是傳值間的問題,意外發現一個規則,就是get多值的狀況 用GET傳遞多個變數 如果要使用GET的方式傳多的變數時,我們會用&的符號來做變數的分隔 http://goo.gl/E3jso

方法三 一切只是&的問題!
if(isset($_GET['now_Page'])){
  $now_Page=$_GET['now_Page'];
}else{
  $now_Page=1;
}

$sort_id = $_GET['sort_id']; //只需要得到sort_id
  //if($_GET['sort_id']){$sort = "?sort_id=".$_GET['sort_id'];}

  //$idx = $s_index;
  //$s_index = $s_index.$sort; 
修改location的連結

就不用改pagecreator參數了
	  <?php

    $where = " where sort_id=".$sort_id." order by seq";

         $sql="select count(*) from ".$s_table.$where ;
    $pageShower=pageCreater($now_Page,10,$sql,$cn,$s_index,"");

        $sql="select * from ".$s_table.$where. " limit ".$record_begin.",".$record_show;
        $result=mysql_query($sql,$cn);
        
        echo $pageShower;
        ?>

Previous
Next Post »