如何使用PHP在url中传递其他参数

时间:2013-09-18 06:52:07

标签: php wordpress

如何在网址中传递其他参数以便分页工作

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

如何在 PHP 中创建语法/逻辑以在网址中添加&pagenum=1

目前我有这段代码

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

3 个答案:

答案 0 :(得分:1)

$pagenum = 1;
$url = "http://localhost/site/wp-admin/admin.php?page=myPage" . "&pagenum=".$pagenum;

答案 1 :(得分:0)

试试这个::

首先构建一个您想要传输的数据数组,如 -

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

然后使用http_build_query将数据转换为url格式!!

$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;

答案 2 :(得分:0)

$page='MyPage';
$pagenum = 1;
$url = "http://localhost/site/wp-admin/admin.php?page=".$page."&pagenum=".$pagenum;
相关问题