 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
02-02-2008, 10:37 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
Pagination without using database ??
I have content-manager which doesnt use database. The contents are being written in a file, and read from the file. Is there anyway to paginate the content ?
the php file:
PHP Code:
<?
require('config.php');
$filename = "article_summary.html";
#- open article summaries
if(file_exists($filename)){
$fh = fopen($filename, "r");
$old_news = fread($fh, filesize($filename));
fclose($fh);
}
#- get first five article
$articles = explode("<!--ARTICLE-->", $old_news);
$i=0;
foreach ( $articles as $article ){
if(count($articles)>$i){
if($max_latest >= $i++){
print $article;
}
}
}
?>
You can see, it uses explode to <!--ARTICLE-->
In the file the <!--ARTICLE--> is between contents.
Example:
In file,
content123 blabla
<!--ARTICLE-->
content456hahaha
<!--ARTICLE-->
content789hehehe
|
|
|
02-03-2008, 01:32 AM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Of course you can paginate your article content. The whole article is just, put simply, a list of blocks of content... just like you can get a list of blocks of content from a database. The pagination system shouldn't really care where the blocks come from at all.
|
|
|
|
02-03-2008, 07:06 AM
|
#3 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
But how can I do it, can you please explain ? I have no idea how to do that....
|
|
|
02-03-2008, 08:52 AM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Explode the text by the separators, and then if there's a GET['page'] (or something like that) set, then output the appropriate element in the array. Something like so:
PHP Code:
$parts = explode( '<!--ARTICLE-->', $text );
$page = isset( $_GET['page'] ) ? intval( $_GET['page'] ) : 0;
echo $parts[$page];
Of course, you might want to enforce some more checks there (like check if the requested page is greater than 0 or 1, depending on how you want the pages to appear, check if the requested page is not greater than the dimension of the array - 1, and so on).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
|
|
|
|
02-03-2008, 10:30 AM
|
#5 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Also you can count the $parts array, and see how many articles you get.
Then you decide how many articles per page you want, and you use some calculations, and voilą! Pagination system :)
__________________
Last edited by Tanax : 02-04-2008 at 10:05 AM.
|
|
|
|
02-03-2008, 11:18 AM
|
#6 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
Thanks.
What I want to do is,
count articles, if articles are more than 5, create page number and then echo the other articles in the other page.
But I cant do it in php language :S
|
|
|
02-03-2008, 11:54 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
I've written a pagination class here:
pagination.php
PHP Code:
<?php
/**
||||||||||||||||||||||||||||||||||||||||||
|||| @author Tanax
|||| @copyright 2008
||||||||||||||||||||||||||||||||||||||||||
**/
class pagination {
// The total value.
private $totalPages;
private $totalResults;
private $totalPerPage;
// The current value.
private $currentPage;
private $currentSpan;
private $firstResult;
public function setMax($max) {
if(is_numeric($max)) {
$this->totalPerPage = $max;
}
}
public function setPage($page) {
if(is_numeric($page)) {
$this->currentPage = mysql_real_escape_string($page);
$this->firstResult = (($this->currentPage * $this->totalPerPage) - $this->totalPerPage);
return $this->firstResult;
}
}
public function getPages($results) {
$this->totalResults = count($results);
$totalPages = $this->totalResults / $this->totalPerPage;
$this->totalPages = ceil($totalPages);
$x = 1;
$array = array();
while($x <= $this->totalPages) {
$array[] = $x;
$x++;
}
return $array;
}
public function checkLink($pagenr) {
if($pagenr <= $this->totalPages && $pagenr >= 1) {
return true;
}
return false;
}
public function getCurrentPage() {
$array = array();
$array[] = $this->currentPage;
$array[] = $this->totalPages;
return $array;
}
}
?>
example.php
PHP Code:
<?php
/**
||||||||||||||||||||||||||||||||||||||||||
|||| @author Tanax
|||| @copyright 2008
||||||||||||||||||||||||||||||||||||||||||
**/
include('pagination.php');
$p = $_GET['p'];
(isset($p)) ? $p : 1;
$max = 10;
// Create the object and set some basic values.
$pagination = new pagination();
$pagination->setMax($max);
// Get the total results, and then calculate how many pages that becomes based on how many results per page.
$totSql = "SELECT * FROM `table`";
$totQuery = mysql_query($totSql) or die(mysql_error());
$totResults = mysql_fetch_array($totQuery);
$totPages = $pagination->getPages($totResults);
// Set the current page, and get the first result on it.
$first = $pagination->setPage($p);
// Get the results of the current page.
$exSql = "SELECT * FROM `table` LIMIT $first, $max";
$exQuery = mysql_query($exSql) or die(mysql_error());
$exResults = mysql_fetch_array($exQuery);
// Echo out the current page, and the total amount of pages.
$page = $pagination->getCurrentPage();
echo 'Page: '.$page[0].' of '.$page[1];
// Get previous page link, and check if it's valid.
$prevLink = $p - 1;
if($pagination->checkLink($prevLink)) {
echo 'Previous Page';
}
// Print all the pages
foreach($totPages as $pageNumber) {
if($pageNumber == $p) {
echo '<strong>'.$pageNumber.'</strong>';
}
else {
echo $pageNumber;
}
}
// Get the next page link, and check if it's valid.
$nextLink = $p + 1;
if($pagination->checkLink($nextLink)) {
echo 'Next Page';
}
// Echo the results...
?>
Ofcourse you have to edit the "Next page" for example, to contain a link to the next page..
The good thing with this pagination class is that it's only the core, and it only generates RESULTS, and NO html tagging.
So you can modify the result page easially by just changing the html tagging in that file. Instead of having to go through the class file and change the html tagging in there..
I haven't written a tutorial or a "how-to-use" for this, but I'm sure you'll understand it, otherwise you can just ask if you hit a problem
Hope it helped.
__________________
Last edited by Tanax : 02-04-2008 at 10:05 AM.
|
|
|
|
|
The Following User Says Thank You to Tanax For This Useful Post:
|
|
02-03-2008, 12:33 PM
|
#8 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
Thanks a lot Tanax. I am gonna test it... But is this using mysql ? If it is, where should I write database settings ? I am not very good in php, just in middle ;) And can you explain how can I paginate without using mysql ? (Get data from file, not from mysql table ?)
|
|
|
02-03-2008, 02:22 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
No it's not using mysql.
My example is using mysql, but the core can work with files too.
You would have to count your results, and set how many results per page you want to show.
PHP Code:
$totPages = $pagination->getPages($totResults);
That's how many pages in total there are based on how many results, and how many results per page you want to show.
$totResults would be count($articles) in your case..
I'm not sure how you would solve the "exQuery" in your case(without mysql), but you would have to come up with some other way to generate the results on the CURRENT page. As you see, I'm not using the class in any of the $ex~ variables..
But other than that you can use my example.php exactly like it is... xD
__________________
Last edited by Tanax : 02-04-2008 at 10:05 AM.
|
|
|
|
02-03-2008, 08:40 PM
|
#10 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
Thanks. I am gonna learn how to
echo pages if the contents are 5+ and show the others in the next page.
|
|
|
02-04-2008, 12:42 AM
|
#11 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Very interesting. Btw I just learned a new term, pagination. It even sounds cool!
|
|
|
|
02-04-2008, 10:04 AM
|
#12 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by ETbyrne
Very interesting. Btw I just learned a new term, pagination. It even sounds cool!
|
hahahahh  It actually does sound cool 
__________________
|
|
|
|
10-18-2012, 02:46 PM
|
#13 (permalink)
|
|
The Addict
Join Date: Oct 2012
Posts: 244
Thanks: 0
|
Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
|
|
|
|
10-18-2012, 02:52 PM
|
#14 (permalink)
|
|
The Addict
Join Date: Oct 2012
Posts: 244
Thanks: 0
|
Some conservatives have Coach Factory Outlet pushed that critique further, saying that Mr. Obama’s policies are too costly, often assist the wrong people Louis Vuitton Belts and could have the paradoxical effect of driving up college costs. The dispute turns not just on different Coach Factory Outlet assessments of how policies play out, but on differing philosophical views about the role of government. During Gucci Belts his time in office, Mr. Obama has sharply increased aid to low- and middle-income students, notably through the Pell Grant Coach Factory Outlet program, which grew from $14.6 billion given to 6 million students in 2008, to nearly $40 billion for Coach Factory Outlet almost 10 million students this year. His administration also made it easier to request aid, shortening the Coach Factory Online complex federal application and allowing people to transfer their financial information electronically from the Internal Coach Outlet Online Revenue Service database. But while many education experts laud his efforts, analysts of varying political Coach Outlet Online stripes have also questioned how much impact some of the president’s policies will have, noting that the prices Coach Online Outlet charged by colleges, and student borrowing, continue to climb.But behind the headlines about soaring costs, the Coach Factory Outlet Online reality is more complex and wildly uneven, because a growing number of students receive Coach Outlet Online financial aid, and only relatively high-income families pay those fast-rising sticker prices. Adjusted for Coach Factory Online inflation, the College Board calculates, the average net price changed little over the last decade at private Coach Factory Outlet schools, and rose only modestly at public ones.Defending federal spending, Arne Duncan, the secretary of Hermes Belts education, said that for more than 30 years, college prices had risen even when federal aid had not, leading him to believe Coach Factory Online there was zero correlation.
|
|
|
|
10-22-2012, 10:17 AM
|
#15 (permalink)
|
|
The Addict
Join Date: Oct 2012
Posts: 244
Thanks: 0
|
when I go home. Coach Outlet It’s a big part of what I find addictive about living and working in Coach Outlet Store Online this part of the world. You feel like you’re watching the future unfold. Coach Factory Online for the US Open with no success."I prefer to go day-by-day without setting objectives or Coach Factory Online time frames, work hard on my recovery and make sure I keep on getting better little by little."Nadal has been forced Coach Outletto watch from the sidelines as longtime rival Roger Federer returned Coach Purse Outlet Onlineto the top of the world rankings after winning Coach Factory Outlet Onlinea seventh Wimbledon singles title.He has also seen Britain's Andy Murray, Coach Bags Outlet Online who won the men's singles gold medal at the 2012 Olympic Games, move above him in the world rankings after securing his Coach Handbags Outlet first grand slam title at last month's U.S. Open.Currently ranked fourth in the world, Nadal has qualified to play at November's season-ending ATP World Tour Finals in London, Coach Outlet Onlinebut his ability to take part is in doubt due to his injury problems, admitting that his knee is still "bothering him".
|
|
|
|
01-29-2013, 12:37 PM
|
#16 (permalink)
|
|
The Addict
Join Date: Oct 2012
Posts: 244
Thanks: 0
|
Organizers said Coach Outlet Online was opportune because the battle’s 150-year anniversary is in December, and Fredericksburg Coach Factory Outlet has been preparing to mark the sesquicentennial. in the new agreement is that Coach Outlet Online revolutionary councils from 14 Syrian provinces now each have a representative, though not all live Coach Online Outlet in Syria. The hope is that will bind the coalition to those inside the country. Perhaps Coach Bags Outlet the most important body the new group is expected to form is a Revolutionary Military Council Coach Factory Online to oversee the splintered fighting organizations and to funnel both lethal and nonlethal Coach Factory Outlet military aid to the rebels. It should unite units of the Free Syrian Army, various militias Coach Outlet Store Online and brigades in each city and large groups of defectors. Before the ink was even dry on the Coach Outlet Store final draft, negotiators hoped that it would bring them the antiaircraft missiles they crave to Coach Factory Stores take on the Syrian Air Force. The United States and Britain have offered only Coach Handbags Outlet nonmilitary aid to the uprising. A similar attempt by the Syrian National Council to Coach Factory Store supervise the military never jelled. Organizers said funding was too haphazard. Eventually foreign Coach Factory Online governments like Qatar and Saudi Arabia, which are financing and arming the rebels, found Coach Factory Online their own favorite factions to deal with. Foreign leaders notably including Secretary of State Coach Outlet Hillary Rodham Clinton urged this unification largely so they could coordinate their Coach Factory Outlet efforts and aid through a group of technocrats. Once it receives international recognition, the Coach Outlet Store Online coalition is supposed to establish a temporary Coach Outlet Online military never jelled.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|