Hey I got problem with my(found) search code.
If I search for something that is split into two columns like Name and Last name,
it only works if the first name is only One name(word).
For example If I got a Name column with two names such as Nancy Dandry,
and a LastName column with 5 names, Tomson Craig John McGee Name,
I can search for it only if I use one name(word) from the Name Column.
Example
:Search Field: Nancy John McGee Name = Results
:Search Field: Dandry Tomson John Tomson = Results
:Search Field: Nancy Dandry = No Results
:Search Field: Nancy Dandry Tomson = No Results.
Basically if the Name column has two or more words and I search for two or more words, I get no results at all.
How do I got about fixing this? I really can't find anyway, I've searched all over...
I believe the Culprit is the little snippet of code below, but I'm not sure.
I've been trying to tackle this issue several times for a few months and given up on it every time :& I've tried all the other options, but this is the closest I've been to solving it... Sounds like I'm building a rocket, but yeah... :)
$output = ' ' ;
$search_exploded = explode (" ", $search);
$x = "";
$construct = "";
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="Name LIKE '%$search_each%'";
else
$construct .="AND LastName LIKE '%$search_each%'";
}
The Form I'm using
<form action='sear.php' method='GET'>
<center>
<h1> Search</h1>
<input type='text' size='50' name='search'></br></br>
<input type='submit' name='submit' value='Search' ></br></br></br>
</center>
</form>
Full Php Code
<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(strlen($search)<=1)
echo "Search term is too short!";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","Name_Name","Password");
mysql_select_db("Database_Test");
$output = ' ' ;
$search_exploded = explode (" ", $search);
$x = "";
$construct = "";
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="Name LIKE '%$search_each%'";
else
$construct .="AND LastName LIKE '%$search_each%'";
}
$constructs ="SELECT * FROM Information WHERE $construct";
$run = mysql_query($constructs);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "Excuse for not finding the result... None";
else
{
echo "$foundnum results found !<p>";
$per_page = 10;
$start = isset($_GET['start']) ? $_GET['start']: '';
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
$getquery = mysql_query("SELECT id, Name, LastName FROM Information WHERE $construct ORDER BY id DESC LIMIT $start, $per_page");
while($runrows = mysql_fetch_assoc($getquery))
{
$id = $runrows ['id'];
$Name = $runrows ['Name'];
$LastName = $runrows ['LastName'];
$output .= ' <div class="Name">' . $Name . ' </div> <div class="LastName">' . $LastName . ' </div> ';
}
//Pagination Starts
echo "<center>";
$prev = $start - $per_page;
$next = $start + $per_page;
$adjacents = 3;
$last = $max_pages - 1;
if($max_pages > 1)
{
//previous button
if (!($start<=0))
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$prev'>Prev</a> ";
//pages
if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$i = 0;
for ($counter = 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if(($start/$per_page) < 1 + ($adjacents * 2))
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $start){
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
{
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=0'>1</a> ";
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $start){
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//close to end; only hide early pages
else
{
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=0'>1</a> ";
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
}
//next button
if (!($start >=$foundnum-$per_page))
echo " <a href='sear.php?search=$search&submit=Search+names+keyword&start=$next'>Next</a> ";
}
echo "</center>";
}
}
?>
You could try a fulltext index across (first_name, last_name), eg:
alter table names add fulltext name (first_name, last_name);
and then query against it like so:
select *
from names
where match (first_name, last_name)
against('+Nancy +Dandry' in boolean mode);
select *
from names
where match (first_name, last_name)
against('+Nancy +Dandry +Tomson'in boolean mode);
select *
from names
where match (first_name, last_name)
against('+Dandry +Tomson +John +Tomson'in boolean mode);
select *
from names
where match (first_name, last_name)
against('+Nancy +John +McGee +Name'in boolean mode);
All of which will return matching rows, whereas:
select *
from names
where match (first_name, last_name)
against('+Nancy +Cylon'in boolean mode);
Will not return any matches, because the + signs in front of the name elements will ensure that only results that match all those word are included. heres an example
Related
I have a php pagination page with post submit by user to search something, query mysql in first page is ok, but in NEXT page, i have get white blank page.
Below is the paging code.
$_SESSION['nationality'] = $_POST['nationality'];
$reclimit = 2;
if(isset($_GET['page'])){
$page = $_GET['page'];
} else {
$page = 1;
}
$start = (($page-1) * $reclimit);
$sql = "SELECT userid, name, LEFT(hkid, 4) as hkid, description, nationality, photo_1, photo_2, photo_3 FROM $tbl_name WHERE `nationality` LIKE '%$_SESSION[nationality]%'";
$records = $con->query($sql);
$total = $records->num_rows;
$tpages = ceil($total / $reclimit);
$rec = "SELECT userid, name, LEFT(hkid, 4) as hkid, description, nationality, photo_1, photo_2, photo_3 FROM $tbl_name WHERE `nationality` LIKE '%$_SESSION[nationality]%' LIMIT $start, $reclimit";
$records = $con->query($rec);
while ($row = mysqli_fetch_assoc($records)){
// Loop record
}
// Paging
echo '<ul class="pagination pagination-lg">';
for( $i=1; $i <= $tpages; $i++ ) {
$active = $i == $page ? 'class="active"' : '';
echo "<li $active ><a href='$_SERVER[PHP_SELF]?page=" .$i. "'>" .$i. "</a></li>";
}
echo '</ul>';
This works for me:
<?php
$limit =3;
if (!isset($_GET['pg'])) {
$pg = 1;
} else {
$pg = $_GET['pg'];
}
$start = ($pg - 1 ) * $limit;
$sql = "SELECT * FROM tableName LIMIT $start , $limit";
?>
I have 114 table Names
sura1
sura2
....
sura114
now I want select query for search engine but wrong select
$run = mysqli_query($mysqli,
"SELECT * FROM (
SELECT * FROM sura1
UNION ALL SELECT * FROM sura2
) WHERE $construct"
);
......
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
define("HOST", "localhost");
define("USER", "root");
define("PASSWORD", "");
define("DATABASE", "holygod");
$mysqli = mysqli_connect(HOST, USER, PASSWORD, DATABASE);
$mysqli->set_charset("utf8");
$search_exploded = explode (" ", $search);
$x = "";
$construct = "";
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="en_arberry LIKE '%$search_each%'";
else
$construct .="AND en_arberry LIKE '%$search_each%'";
}
$run = mysqli_query($mysqli,"SELECT * FROM ( SELECT * FROM sura1 UNION ALL SELECT * FROM sura2) WHERE $construct");
$foundnum = mysqli_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
else
{
echo "$foundnum results found !<p>";
$per_page = 6;
$start = isset($_GET['start']) ? $_GET['start']: '';
$max_pages = ceil($foundnum / $per_page);
if(!$start)
$start=0;
//$getquery = mysqli_query($mysqli,"SELECT * FROM sura2 WHERE $construct LIMIT $start, $per_page");
$getquery = mysqli_query($mysqli,"SELECT * FROM ( SELECT * FROM sura1 UNION ALL SELECT * FROM sura2) WHERE $construct LIMIT $start, $per_page");
while($runrows = mysqli_fetch_assoc($getquery))
{
$sura_num = $runrows ['sura_num'];
$en_arberry = $runrows ['en_arberry'];
$sura_name_fa = $runrows ['sura_name_fa'];
echo "
<a href='$sura_name_fa'><b>$sura_num</b></a><br>
$en_arberry<br>
<a href='$sura_name_fa'>$sura_name_fa</a><p>
";
}
//Pagination Starts
echo "<center>";
$prev = $start - $per_page;
$next = $start + $per_page;
$adjacents = 3;
$last = $max_pages - 1;
if($max_pages > 1)
{
//previous button
if (!($start<=0))
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$prev'>Prev</a> ";
//pages
if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
$i = 0;
for ($counter = 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if(($start/$per_page) < 1 + ($adjacents * 2))
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2))
{
echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
//close to end; only hide early pages
else
{
echo " <a href='search.php?search=$search&submit=Search+source+code&start=0'>1</a> ";
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$per_page'>2</a> .... ";
$i = $start;
for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $start){
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$i'>$counter</a> ";
}
$i = $i + $per_page;
}
}
}
//next button
if (!($start >=$foundnum-$per_page))
echo " <a href='search.php?search=$search&submit=Search+source+code&start=$next'>Next</a> ";
}
echo "</center>";
}
}
I strongly suggest looking into different database partitioning methods.
Since I'm assuming the tables have the same design.
Then there won't be a need to create joins or track which table to use.
http://en.wikipedia.org/wiki/Partition_%28database%29
http://dev.mysql.com/doc/refman/5.6/en/partitioning.html
my default load page is ok with next and prev results.. but for search results i can get only first page then blank for the next page. let say total search results row is 9, it display 3 pages with next link. but when i click the next link, it queries no result on the page 2. here is my code:
echo '<table><tr><td>';
echo '<form method="post" name="frmSearch" action="mypage.php>
Search by name
<input type="text" name="txtSearch">
<input type="submit" name="submit" value="Search">
</form>';
$per_page = 5;
$page = 1;
if (isset($_GET['page']))
{
$page = intval($_GET['page']);
if($page < 1) $page = 1;
}
$start_from = ($page - 1) * $per_page;
$Prev_Page = $page - 1;
$Next_Page = $page + 1;
if (!$_POST){
//$sql = "SELECT * FROM mytable LIMIT $start_from, $per_page";
//$totalr = mysql_query("SELECT COUNT(*) FROM mytable");
//$totalr = mysql_fetch_row($totalr);
//$totalr = $totalr[0];
//$total_pages = $totalr / $per_page;
//$total_pages = ceil($total_pages);
//$listresult = mysql_query($sql);
//$total = mysql_num_rows($listresult);
}
else {
if ($_POST['txtSearch']!="") {$cond1 = " name LIKE
'%".$_POST['txtSearch']."%' ";} else {$cond1 = 1; }
$sql = "SELECT * FROM mytable WHERE ".$cond1." LIMIT $start_from, $per_page";
$totalr = mysql_query("SELECT COUNT(*) FROM mytable WHERE name LIKE
'%".$_POST['txtSearch']."%' ");
$totalr = mysql_fetch_row($totalr);
$totalr = $totalr[0];
$total_pages = $totalr / $per_page;
$total_pages = ceil($total_pages);
$listresult = mysql_query($sql);
$total = mysql_num_rows($listresult);
}
if($total == 0){
echo "<center>No records found.</center>";
}
echo "<span style='float:right;margin-top:8px;'>[ <a href='new.php'>Add New</a>
]</span></td></tr>";
echo "<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
";
while ($_POST = mysql_fetch_assoc($listresult)){
echo "<tr>";
echo "<td>" . $_POST['id'] . "</td>";
echo "<td>" . $_POST['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</table>";
echo $totalr." result";
echo "<br>";
if ($Prev_Page) {
echo " <a href ='{$_SERVER['PHP_SELF']}?page=$Prev_Page'><< Prev</a> ";
}
if ($totalr > $per_page) {
for($i = 1; $i <= $total_pages; ++$i)
{
echo "<a href='{$_SERVER['PHP_SELF']}?page=$i'>$i</a> | ";
}
}
if ($page!=$total_pages) {
echo " <a href='{$_SERVER['PHP_SELF']}?page=$Next_Page'>Next >></a> ";
}
maybe you need to use SELECT COUNT(*) FROM mytable WHERE name LIKE '%$search%' ... remember to escape the $_POST['txtSearch']
I am unable to do pagination. The code display all the data retrieve from the mysql. Please help me to get it right.....
function.php
function pagination($limit=5) //here limit is not taken by the code
{
//$limit=5; if I uncomment this line limit will work
global $admin;
$sql = "SELECT FOUND_ROWS();";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$numrows = $row[0];
$pagelinks = "<div class=pagelinks>";
if ($numrows > $limit) {
if(isset($_GET['page'])){
$page = $_GET['page'];
} else {
$page = 1;
}
$currpage = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
$currpage = str_replace("&page=".$page,"",$currpage);
if($page == 1){
$pagelinks .= "<span class='pageprevdead'>< PREV</span>";
}else{
$pageprev = $page - 1;
$pagelinks .= "<a class='pageprevlink' href='" . $currpage .
"&page=" . $pageprev . "'>< PREV</a>";
}
$numofpages = ceil($numrows / $limit);
$range = $admin['pageRange']['value'];
if ($range == "" or $range == 0) $range = 7;
$lrange = max(1,$page-(($range-1)/2));
$rrange = min($numofpages,$page+(($range-1)/2));
if (($rrange - $lrange) < ($range - 1)) {
if ($lrange == 1) {
$rrange = min($lrange + ($range-1), $numofpages);
} else {
$lrange = max($rrange - ($range-1), 0);
}
}
if ($lrange > 1) {
$pagelinks .= "..";
} else {
$pagelinks .= " ";
}
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
$pagelinks .= "<span class='pagenumdead'>$i</span>";
}else{
if ($lrange <= $i and $i <= $rrange) {
$pagelinks .= "<a class='pagenumlink' href='" . $currpage .
"&page=" . $i . "'>" . $i . "</a>";
}
}
}
if ($rrange < $numofpages) {
$pagelinks .= "..";
} else {
$pagelinks .= " ";
}
if(($numrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
$pagelinks .= "<a class='pagenextlink' href='" . $currpage .
"&page=" . $pagenext . "'>NEXT ></a>";
} else {
$pagelinks .= "<span class='pagenextdead'>NEXT ></span>";
}
} else {
$pagelinks .= "<span class='pageprevdead'>
< PREV</span> ";
$pagelinks .= "<span class='pagenextdead'>
NEXT ></span> ";
}
$pagelinks .= "</div>";
return $pagelinks;
}'
index.php
$sql = "SELECT id FROM articles WHERE is_published=1 " .
"ORDER BY date_published DESC"; //this is the query to retrive data from mysql
$result = mysql_query($sql,$conn);
if (mysql_num_rows($result) == 0) {
echo " <br />\n";
echo " There are currently no articles to view.\n";
} else {
while ($row = mysql_fetch_array($result)) {
outputStory($row['article_id'],TRUE);
}
}
echo pagination($limit);`
This code is incomplete. However the first thing you need to do is add the $limit to the actual sql query:
$sql = "SELECT id FROM articles WHERE is_published=1 " .
"ORDER BY date_published DESC LIMIT {$limit}";
Try this.
Just create a mysql table called players with 3 fields:- id, firstname, lastname to check how the code is working.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View Records</title>
</head>
<body>
<?php
/*
VIEW-PAGINATED.PHP
Displays all data from 'players' table
This is a modified version of view.php that includes pagination
*/
// connect to the database
include('dbconfig.php');
// number of results to show per page
$per_page = 2;
// figure out the total pages in the database
$result = mysql_query("SELECT * FROM players");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['page']) && is_numeric($_GET['page']))
{
$show_page = $_GET['page'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// display pagination
echo "<p><a href='view.php'>View All</a> | <b>View Page:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='view-paginated.php?page=$i'>$i</a> ";
}
echo "</p>";
// display data in table
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'id') . '</td>';
echo '<td>' . mysql_result($result, $i, 'firstname') . '</td>';
echo '<td>' . mysql_result($result, $i, 'lastname') . '</td>';
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo "</tr>";
}
// close table>
echo "</table>";
// pagination
?>
<p>Add a new record</p>
</body>
</html>
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
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> ";
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> ";
// …