Hello everyone, My name is Love (for real) & I am very new to the community and have actually found this forum by searching google for some help with a certain php code that I am dying to understand and use.
As indicated on my title, you must already have assumed what code I'm hoping to work with. I'm not very knowledgeable with php, however I know how to use very simple codes such as includes which have helped me a lot with my site.
Anyway, yes, I was wondering how to divide my pages and have them all automatically linked in a Previous / Next option at the top of each of their page.
Ex:
<< Prev | 1 2 3 4 5 | Next >>
So far, I have only been using includes to have this kind of effect on my site with categories which have numerous pages, but it is not automated & everytime I update (add a new page) I would have to edit the included php page to add the new page link, also I cannot work with a Previous & Next option.
I would not have asked for help had I known how to use the codes provided in the following threads: Pagination, Prev / Next Buttons,Paging Class.
I am very eager to use the codes which have been shared but I'm afraid such threads did not make room for the new learners & only cater to those who are already very able in php.
Therefore, I have decided to seek guidance, only with very basic questions that I am sure everyone has overlooked to emphasize on because of its clarity to experienced coders like yourselves.
I am interested in using this code by Batman (found on the 2nd thread) because it seems to be the most simple one amongst the others & it also shows 1-5 pages which is what I'm hoping to get:
// limit value for number of records to be shown per page
// query database to find total number of records to display
$limit = 5;
$query_count = "select * from ".$prefix."store_inventory where (description like '%$search%' or title like '%$search%')";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page))
$page = 1;
$limitvalue = $page * $limit - ($limit);
$query = "select * from ".$prefix."store_inventory where (description like '%$search%' or title like '%$search%') LIMIT $limitvalue, $limit ";
$result = mysql_query($query) or die("Error: " . mysql_error());
$count_result = mysql_num_rows($result);
// Display links at the top to indicate current page and number of pages displayed
$numofpages = ceil($totalrows / $limit);
echo"<br><p><b>$totalrows</b> result(s) for: \"$search\"</p>";
$from=$limit*$page-$limit+1;
$to=$from + $count_result-1;
// start 123 next>> table
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"left\">";if($numofpages>1){echo"Showing: $from - $to</td><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"right\"><b>Go to page:</b> ";}
// display previous link if page is not 1
if($page != 1){
$pageprev = $page - 1;
echo("<a href=\"$PHP_SELF?page=$pageprev&search=$search\"><< PREV</a> ");
}
// display page nos if not 1
for($i = 1; $i <= $numofpages; $i++){
if($numofpages>1){
if($i == $page)
echo(" ".$i." ");
else
echo(" <a href=\"$PHP_SELF?page=$i&search=$search\">$i</a> ");
}}
// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo("<a href=\"$PHP_SELF?page=$pagenext&search=$search\">NEXT >></a>");
}
// end 123 next>> table
echo"</td></tr></table><br>";
My questions are the following:
Code Questions:
1. Do I paste the code on an empty page?
What filename should I use on the page with the code?
Do I make this page an include for all the pages I am going to use the code on?
I notice the code does not begin with a < nor does it end with a >, what should be done must already seem very obvious to you, but am I expected to add codes prior and after the provided code?
If so - what should I add?
Page Questions:
1. Should my pages be named a certain way? (eg. page1.php, page2.php, page3.php etc)
Should I make a separate directory / folder for each batch of pages of the same category?
(Example: If the category is Graphics, am I required to make a folder named "Graphics" and have each of my pages inside this directory?)
Apart from all the page questions above, should I even actually make numerous pages, or should I just make 1 page & put all the content in there and leave it for the code to divide in multiple pages?
-If I should only be making one page, how do I order my content so the code can divide it, or can see which goes on the 1st page and which goes to the 2nd, so on & so forth.
Other Questions:
1. What else is required for me to do in order to get the code working?
- If my questions are completely clueless, would you mind pushing me towards the right path and clue me in?
As you can see, all these questions are noob types, but unfortunately, none of them were answered or discussed in the 3 popular threads which must mean the answers are understandable & too obvious to be mentioned so I hope you guys will help me out here. 🙂
Thanks!