You are here: Re: Page system help. « PHP Programming Language « IT news, forums, messages
Re: Page system help.

Posted by kay on 12/18/93 11:51

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);
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация