0

如何在 url 中传递附加参数以使分页工作

我现有的页面链接是http://localhost/site/wp-admin/admin.php?page=myPage

如何在PHP中创建语法/逻辑以添加&pagenum=1到 url?

目前我有这个代码

global $wpdb;

$per_page = 6;
$page_query = $wpdb->get_var("SELECT COUNT('id') FROM form"); 

$pages = ceil($page_query / $per_page);

$currentPage = (isset ($_GET['pagenum'])) ? (int)$_GET['pagenum'] : 1;
$start = ($currentPage -1 ) * $per_page;

$row = $wpdb->get_results("SELECT * FROM form LIMIT $start , $per_page");

//foreach loop here
4

3 回答 3

1
$pagenum = 1;
$url = "http://localhost/site/wp-admin/admin.php?page=myPage" . "&pagenum=".$pagenum;
于 2013-09-18T06:55:33.483 回答
0

Try this::

First build an array of data you want to transfer like--

$data=array(
 "param1"=>"value1",
 "param2"=>"value2"
);

Then use http_build_queryto convert data to url format!!

$url_data=http_build_query($data);
$target_url="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // your url here
if(strpos($target_url,"?")==false){
   $target_url.="?";
}else{
   $target_url.="&";
}
$target_url.=$url_data;
于 2013-09-18T07:14:44.813 回答
0
$page='MyPage';
$pagenum = 1;
$url = "http://localhost/site/wp-admin/admin.php?page=".$page."&pagenum=".$pagenum;
于 2013-09-18T07:32:43.800 回答