Hello, i want to change te result of showing in the browser,
now it shows this when i click 2 3 4 or next.

Search+source+code&page=36
Search+source+code&page=72
Search+source+code&page=108

and i want to change it to this,

Search+source+code&page=2
Search+source+code&page=3
Search+source+code&page=4

If i change $per_page = 36; to $per_page = 1; than works everything fine but than i dont have 36 videos but 1. and i want to show 36 videos, here below is the complete script.

<?php

$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>";
mysql_connect("mysql_host_name","mysql_username","mysql_password");
mysql_select_db("database_name");

$search_exploded = explode (" ", $search);

foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="title LIKE '%$search_each%'";
else
$construct .="AND title LIKE '%$search_each%'";

}

$constructs ="SELECT * FROM database_table_name WHERE $construct";
$run = mysql_query($constructs);

$foundnum = mysql_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 = 36;
$page = $_GET["page"];
$max_pages = ceil($foundnum / $per_page);
if(!$page)
$page=0;
$getquery = mysql_query("SELECT * FROM database_table_name WHERE $construct LIMIT $page, $per_page");

while($runrows = mysql_fetch_assoc($getquery))
{
$title = $runrows ["title"];
$desc = $runrows ["description"];
$url = $runrows ["url"];

echo "
<a href='$url'><b>$title</b></a><br>
$desc<br>
<a href='$url'>$url</a><p>
";

}

//Pagination pages
echo "<center>";

$prev = $page - $per_page;
$next = $page + $per_page;

$adjacents = 3;
$last = $max_pages - 1;

if($max_pages > 1)
{ 
//previous button
if (!($page<=0))
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$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 == $page){
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$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(($page/$per_page) < 1 + ($adjacents * 2))       
{
$i = 0;
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($i == $page){
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> ";
}
$i = $i + $per_page;                                     
}

}
//in middle; hide some front and some back
elseif($max_pages - ($adjacents * 2) > ($page / $per_page) && ($page / $per_page) > ($adjacents * 2))
{
echo " <a href='search.php?search=$search&submit=Search+source+code&page=0'>1</a> ";
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... ";

$i = $page;               
for ($counter = ($page/$per_page)+1; $counter < ($page / $per_page) + $adjacents + 2; $counter++)
{
if ($i == $page){
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$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&page=0'>1</a> ";
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... ";

$i = $page;               
for ($counter = ($page / $per_page) + 1; $counter <= $max_pages; $counter++)
{
if ($i == $page){
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> ";
}
else {
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; 
}
$i = $i + $per_page;             
}
}
}

//next button
if (!($page >=$foundnum-$per_page))
echo " <a href='search.php?search=$search&submit=Search+source+code&page=$next'>Next</a> ";   
} 
echo "</center>";
}
}
?>

Thank in advance

Member Avatar for LastMitch

You know you are asking 2 different things at the same time.

Search+source+code&page=36
Search+source+code&page=72
Search+source+code&page=108

page=36 means you have 36 videos on the page.

and I want to change it to this

Search+source+code&page=2
Search+source+code&page=3
Search+source+code&page=4

page=1 means that 1 is an id in your database but the code you provide means that 36 video is on the id=1 another 36 video (72) is on id=2

than works everything fine but than i dont have 36 videos but 1. and i want to show 36 videos, here below is the complete script.

What do you want?

The code you provide is written to fit 36 videos but you want to change the url from 36 to 1 but you still want 36 videos to appear?

The code you provide is written to fit 36 videos but you want to change the url from 36 to 1 but you still want 36 videos to appear?

Yes.

Member Avatar for LastMitch

This is how your table looks like:

Table: database_table_name

 id | page
 ---------
 1  |  36
 2  |  72
 3  | 108

Did you write this code?

You only need is to switch (change) the page=$i into page=$id

Something like this:

echo "<a href='search.php?search=$search&submit=Search+source+code&page=$id'><b>$counter</b></a>";

So your URL should look like this:

search.php?search=$search&submit=Search+source+code&page=1

I dont write it alone, i asked a litle bit help because i am new to php.

I change it and now i have

  1. search.php?search=$search&submit=Search+source+code&page=

Do i need to change everywhere like on line 143 also ?

beacause i changed only this

  1. echo "<a href='search.php?search=$search&submit=Search+source+code&page=$id'><b>$counter</b></a>";

Thanks for your comment.

Member Avatar for LastMitch

Do i need to change everywhere like on line 143 also ?

You mean this line:

$i = $i + $per_page; 

change it to

$i = $id + $per_page; 

You're not changing much of the code you are just tweaking it by change all of the links from $i to $id because you want to echo the $id number which is 1 not the page which has 36.

Thanks for your reponse, but now is the pagination pressed and when i click on it it stays on the same page.

Member Avatar for LastMitch

Thanks for your reponse, but now is the pagination pressed and when i click on it it stays on the same page.

I know you mention new but how new?

I thought that is what you want. You want to tweak the URL? Did it work?

You need to make change the in $page function using by $id.

$prev = $page - $per_page;
$next = $page + $per_page;

I already change $page to $id and it is beter than page=36 page=72 etc. now you see id=36 id=72 etc, and if people watch to the browser they dont know wich page they are they wil know it only when they watch at the pagination. i have posted this script on many forums and it seems that nobody knows how to change it. I'm tired to ask help for this script, and i cant find a script like other script from the web. If anyone can solve my problem I will be grateful.
@LastMitch Thanks for your responsse

Member Avatar for LastMitch

I already change $page to $id and it is beter than page=36 page=72 etc. now you see id=36 id=72 etc, and if people watch to the browser they dont know wich page they are they wil know it only when they watch at the pagination.

How long have you learn PHP & MYSQL? You mention new but how long?

You have to understand you need to understand some basic query and php code.

Noone will write or modify the whole code for you!

I don't think you read what I wrote from my previous thread:

Does this data look exactly like your table:

Table: database_table_name

id | page
---------
1  |  36
2  |  72
3  | 108

or it looks like this:

Table: database_table_name

 id  | page
-----------
 36  |  36
 72  |  72
108  | 108

Right now, you are telling me that your id = 36 in your table?

Can you look at your table and see what is the $id valve is for row 1?

Row 1 is either id = 1 or id = 36

 id | page    id | page
-----------  ----------
  1 |  36     36 |  36
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.