亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php 檢查 url 中是否存在變量并替換值

php 檢查 url 中是否存在變量并替換值

PHP
達令說 2023-11-05 15:42:01
我寫了一個函數,允許我進行分頁。問題來了:當我單擊按鈕將頁面更改為 URL 時,會添加許多相同的值,如下所示:時事通訊.php?action=sent-emails&page=2&page=1&page=4&page=5&page=7&page=5&page=1function pagination($sql_general,$page_name_pagination,$page_query_pagination) {  require $_SERVER['DOCUMENT_ROOT'] . 'it/intranet/includes/dbh.inc.php';  $sql1 =  $sql_general;  $sql1_query = mysqli_query($conn, $sql1);  $total = mysqli_num_rows($sql1_query);  $adjacents = 3;  $targetpage = $page_name_pagination; //your file name  if (!empty($page_query_pagination)) {    $targetpage .= "?" . $page_query_pagination . "&page=";  } else {    $targetpage .= "?page=";  }  $limit = 10; //how many items to show per page  $page = $_GET['page'];  if($page){  $start = ($page - 1) * $limit; //first item to display on this page  }else{  $start = 0;  }  /* Setup page vars for display. */  if ($page == 0) $page = 1; //if no page var is given, default to 1.  $prev = $page - 1; //previous page is current page - 1  $next = $page + 1; //next page is current page + 1  $lastpage = ceil($total/$limit); //lastpage.  $lpm1 = $lastpage - 1; //last page minus 1  $pagination = "";  if($lastpage > 1)  {  $pagination .= "<div class='pagination1'> <ul class='pagination'>";  if ($page > $counter+1) {  $pagination.= "<li class='page-item'><a class='page-link' href=\"$targetpage$prev\"><</a></li>";  }  if ($lastpage < 7 + ($adjacents * 2))  {  for ($counter = 1; $counter <= $lastpage; $counter++)  {  if ($counter == $page)  $pagination.= "<li class='page-item'><a class='page-link' href='#' >$counter</a></li>";  else  $pagination.= "<li class='page-item'><a class='page-link' href=\"$targetpage$counter\">$counter</a></li>";  }  }  elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some  {現在,如何檢查“page=x”是否存在并替換該值?
查看完整描述

1 回答

?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

拆分、修改/添加和撰寫:


parse_str($query_string,$list);

if (isset($list['name'])

{

     // name= exists, modify it

}

else

{

     // name= not exists

     $list['name'] = "new value";

}

$query_string = http_build_query($list);


查看完整回答
反對 回復 2023-11-05
  • 1 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號