views:

16

answers:

2

I'm using this script to pagination. But when url does have $_GET['word'] I cant change URL's of Links. How can I do it?

<?
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
?>

I'm trying to do if isset $_GET['word'] set urls <a href='{$_SERVER['PHP_SELF']}?word=$word&page=$lastpage'>»»</a> if NOT <a href='{$_SERVER['PHP_SELF']}?page=$lastpage'>»»</a> i cant let it work thank you if you will help

A: 

Try following:

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

And then just append $word_str to urls, for example

 echo " <a href='{$_SERVER['PHP_SELF']}?sayfa='.$nextpage.$word_str.'>»</a> ";
a1ex07
thank you for your answer. :)
Ronnie Chester Lynwood
A: 

You should better use $_SERVER['REQUEST_URI'] to get the current requested URI path and query. You can then use parse_url to get just the URI path and http_build_query to build the query from an array:

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

// …
Gumbo