By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Page system help.

P: n/a
Is it possible to add a page system like:

"< 1-2-3-4-5 >" or "<PREV - NEXT>
To a page thats already written out, or will it be too much work?

For example:

5 articles per page (homepage)... If someone wanted to see the previous
5 articles they could click the "see last 5" or "older posts" instead
of looking through the archive.

Because I put an image with every post. That would waste serious
bandwidth to load every article at once.

Too see what I am talking about, check my site at http://menomore.com

Im looking for a simple solution, any help would be appreciated though.

Thanks,
Mike

Jun 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
kay
Mike написав:
Is it possible to add a page system like:

"< 1-2-3-4-5 >" or "<PREV - NEXT>
To a page thats already written out, or will it be too much work?

For example:

5 articles per page (homepage)... If someone wanted to see the previous
5 articles they could click the "see last 5" or "older posts" instead
of looking through the archive.

Because I put an image with every post. That would waste serious
bandwidth to load every article at once.

Too see what I am talking about, check my site at http://menomore.com

Im looking for a simple solution, any help would be appreciated though.

Thanks,
Mike


In order to make this script flexible you have to find a way to order
your articles. For example it could be done using MySql. You just
regard each article as a record in corresponding table in mysql. The
simple SQL for such table is as follows:

<code>
CREATE TABLE `news` (
`id` tinyint(4) NOT NULL auto_increment,
`titla` varchar(40) NOT NULL default '',
`text` text NOT NULL,
`date` date NOT NULL default '0000-00-00',
`picture` varchar(40) NOT NULL default '',
PRIMARY KEY (`id`)
)
</code>

The powerfull tool in MySQl is to make "limits" queries. For example
the following query:
<code>
select * from `news` limit 0,5
</code>
means that you will receive 5 records starting with 0.

Now lets generate the line <1-2-3-4-5> for page system. At first we
have to calculate the total number of articles.
<?
$res=mysq_query("select cound(id) as count from `news`") or
die("Query failed: " . mysql_error());;
$count=mysq_fetch_array($res);
// now the variable $count["count"] contains our information
// let $page be global variable for the page where we stopped at the
moment

if (!isset($page)) $page=1;

if ($page>5)
{
$pp=$page-$page%5-1;
echo("<a href=\"index.php?page=$pp\">Prev</a>");
}
for ($i=0;$i<5;$i++)
{
$pp=$page+$i;
echo("<a href="\index.php?page=$pp\">$pp</a>");
}

if ($page+4<$count["count"])
{
$pp=$page+5;
echo("<a href=\"index.php?page=$pp\">Prev</a>");
}

// and at last mysq - query

$res=mysql_query("select * from `news` order by `id` desc limit
$page , 1");
$ob=mysql_fetch_object($res);
print_r($ob);
?>

Jun 27 '06 #2

P: n/a
On 26 Jun 2006 17:05:50 -0700, "Mike" <ex*************@gmail.com>
wrote:
Too see what I am talking about, check my site at http://menomore.com


"Error 403: Forbidden!
The server understood the request, but is refusing to fulfill it.
Authorization will not help and the request SHOULD NOT be repeated.

"
--
Locate your Mobile phone: <http://www.bizorg.co.uk/news.html>
Great gifts: <http://www.ThisBritain.com/ASOS_popup.html>
Jun 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.