如何更改网址为每个使用isset与分页?

我使用这个脚本分页。 但是,当URL确实有$ _GET ['字']我不能改变的URL链接。 我该怎么办呢?

<? if (isset($_GET['page']) ) { $pageno = $_GET['page']; } else { $pageno = 1; } // if $limit = ""; if(isset($_GET['word'])) { $word = mysql_real_escape_string($_GET['word']); $word = $word{0}; $limit = " WHERE baslik LIKE '$word%'"; } $query = mysql_query("SELECT count(*) FROM m3_music_mp3" .$limit); $query_data = mysql_fetch_row($query); $numrows = $query_data[0]; $rows_per_page = 30; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // if if ($pageno < 1) { $pageno = 1; } // if $limit .= " ORDER BY id DESC LIMIT " .($pageno - 1) * $rows_per_page .',' .$rows_per_page; //$limit = 'ORDER BY id DESC LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = mysql_query("SELECT * FROM m3_music_mp3 $limit"); if ($pageno == 1) { echo "<a>««</a> <a>«</a> "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=1'>««</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$prevpage'>«</a> "; } // if for($page_number = 1; $page_number <= $lastpage; $page_number++) if($page_number == $pageno) { echo "<span class='current'>$pageno</span>"; } else { echo "<a href='{$_SERVER['PHP_SELF']}?sayfa=$page_number' class='page' title='$page_number'>$page_number</a>"; } if ($pageno == $lastpage) { echo " <a>»</a> <a>»»</a> "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$nextpage'>»</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?sayfa=$lastpage'>»»</a> "; } // if ?>

我想要做的,如果使用isset $ _GET ['字']设置网址<a href='{$_SERVER['PHP_SELF']}?word=$word&page=$lastpage'>»»</a>如果没有<a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>»»</a>我不能让它工作,感谢你,如果你将有助于

--------------解决方案-------------

请尝试以下操作:

$word_str = "";
if(isset($_GET['word'])) {
$word_str = "&word=".$_GET['word'];
//......
}

然后就是追加$word_str到URL,例如

echo " <a href='{$_SERVER['PHP_SELF']}?sayfa='.$nextpage.$word_str.'>»</a> ";

你应该更好地使用$_SERVER['REQUEST_URI']获取当前请求的URI路径和查询。 然后,您可以用parse_url得到公正的URI路径和http_build_query搭建起一个数组查询:

$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// …

$href = htmlspecialchars($_SERVER['REQUEST_URI_PATH']."?".http_build_query(array('sayfa'=>1)+$_GET), ENT_QUOTES);
echo " <a href='$href'>««</a> ";
$prevpage = $pageno-1;
$href = htmlspecialchars($_SERVER['REQUEST_URI_PATH']."?".http_build_query(array('sayfa'=>$prevpage)+$_GET), ENT_QUOTES);
echo " <a href='$href'>«</a> ";

// …

分类:php 时间:2015-03-14 人气:0
本文关键词: PHP,MySQL和分页
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.745 (s). 10 q(s)