PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > split in to multiple pages (I think)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
split in to multiple pages (I think)

Réponse
 
LinkBack Outils de la discussion
Vieux 15/09/2007, 14h16   #1
Joker7
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut split in to multiple pages (I think)

Hi,
I'm using the code below to display news articles-which works great apart
from. I can control the number of articles,but I would like to add a link to
the bottom of the page to the un-displayed articles ( nexted 5 articles and
so on) any pointers would be most welcome as most know my PHP skills are not
the best .

Cheers
Chris


<?

$max_latest = 5;
$filename = "articlesum.php";

#- open article
if(file_exists($filename)){
$fh = fopen($filename, "r");
$old_news = fread($fh, filesize($filename));
fclose($fh);
}
#- get article
$articles = explode("<!--ARTICLE-->", $old_news);

$i=0;
foreach ( $articles as $article ){
if(count($articles)>$i){
if($max_latest >= $i++){
print $article;
}
}
}

?>
--
Cheap As Chips Broadband http://yeah.kick-butt.co.uk
Superb hosting & domain name deals http://host.kick-butt.co.uk
  Réponse avec citation
Vieux 15/09/2007, 16h24   #2
Greg Donald
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] split in to multiple pages (I think)

On Sat, 15 Sep 2007, Joker7 wrote:
> I'm using the code below to display news articles-which works great apart
> from. I can control the number of articles,but I would like to add a link to
> the bottom of the page to the un-displayed articles ( nexted 5 articles and
> so on) any pointers would be most welcome as most know my PHP skills are not
> the best .


There's a bunch of how-tos and discussion on this topic already:

http://google.com/search?q=php+pagination

You have to manage a variable across page requests to keep track of
where you are. Use that variable in your SQL as part of your
offset/limit parameters.


--
Greg Donald
Cyberfusion Consulting
http://cyberfusionconsulting.com/
  Réponse avec citation
Vieux 16/09/2007, 11h43   #3
Thomas Bachmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: split in to multiple pages (I think)

Why don't post an example of your news file too?

Joker7 schrieb:
> Hi,
> I'm using the code below to display news articles-which works great apart
> from. I can control the number of articles,but I would like to add a link to
> the bottom of the page to the un-displayed articles ( nexted 5 articles and
> so on) any pointers would be most welcome as most know my PHP skills are not
> the best .
>
> Cheers
> Chris
>
>
> <?
>
> $max_latest = 5;
> $filename = "articlesum.php";
>
> #- open article
> if(file_exists($filename)){
> $fh = fopen($filename, "r");
> $old_news = fread($fh, filesize($filename));
> fclose($fh);
> }
> #- get article
> $articles = explode("<!--ARTICLE-->", $old_news);
>
> $i=0;
> foreach ( $articles as $article ){
> if(count($articles)>$i){
> if($max_latest >= $i++){
> print $article;
> }
> }
> }
>
> ?>

  Réponse avec citation
Vieux 18/09/2007, 15h43   #4
Joker7
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] split in to multiple pages ( pagination)

In news: Pine.LNX.4.64.0709151021110.30917@de...e planet.host
- Greg Donald wrote :
>> On Sat, 15 Sep 2007, Joker7 wrote:
>>> I'm using the code below to display news articles-which works great
>>> apart from. I can control the number of articles,but I would like
>>> to add a link to the bottom of the page to the un-displayed
>>> articles ( nexted 5 articles and so on) any pointers would be most
>>> welcome as most know my PHP skills are not the best .

>>
>> <?
>>
>> $max_latest = 5;
>> $filename = "articlesum.php";
>>
>> #- open article
>> if(file_exists($filename)){
>> $fh = fopen($filename, "r");
>> $old_news = fread($fh, filesize($filename));
>> fclose($fh);
>> }
>> #- get article
>> $articles = explode("<!--ARTICLE-->", $old_news);
>>
>> $i=0;
>> foreach ( $articles as $article ){
>> if(count($articles)>$i){
>> if($max_latest >= $i++){
>> print $article;
>> }
>> }
>> }
>>
>>>

>> There's a bunch of how-tos and discussion on this topic already:
>>
>> http://google.com/search?q=php+pagination
>>
>> You have to manage a variable across page requests to keep track of
>> where you are. Use that variable in your SQL as part of your
>> offset/limit parameters.
>>
>>
>> --
>> Greg Donald
>> Cyberfusion Consulting
>> http://cyberfusionconsulting.com/



Thanks for the reply - I now know what it's called

I forgot to and it's a flat file system not the best but is ok for my needs.

I spent a couple of hours following link from google an not a sausage on
flat files

Chris
  Réponse avec citation
Vieux 18/09/2007, 16h10   #5
Joker7
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: split in to multiple pages (I think)

In news: CC.25.58774.9E80DE64@pb1.pair.com - Thomas Bachmann wrote :
>> Why don't post an example of your news file too?
>>
>> Joker7 schrieb:
>>> Hi,
>>> I'm using the code below to display news articles-which works great
>>> apart from. I can control the number of articles,but I would like
>>> to add a link to the bottom of the page to the un-displayed
>>> articles ( nexted 5 articles and so on) any pointers would be most
>>> welcome as most know my PHP skills are not the best .
>>>
>>> Cheers
>>> Chris
>>>
>>>
>>> <?
>>>
>>> $max_latest = 5;
>>> $filename = "articlesum.php";
>>>
>>> #- open article
>>> if(file_exists($filename)){
>>> $fh = fopen($filename, "r");
>>> $old_news = fread($fh, filesize($filename));
>>> fclose($fh);
>>> }
>>> #- get article
>>> $articles = explode("<!--ARTICLE-->", $old_news);
>>>
>>> $i=0;
>>> foreach ( $articles as $article ){
>>> if(count($articles)>$i){
>>> if($max_latest >= $i++){
>>> print $article;
>>> }
>>> }
>>> }


Here you go Thomas- not mine I found it on the www.
Im sorry I started using this now would have been a lot better to use mysql.

Chris

<?
include ("template.inc");
include ("config.php");

$subject = $_POST[subject];
$summary = $_POST[summary];
$passwd = $_POST[passwd];
$date = $_POST[date];
$body = $_POST[body];
$article_id = $_POST[article_id];

#foreach($GLOBALS as $a => $b){ print "<li>$a => $b";}

$summary_template = "t_summary.tp";
$article_template = "t_article.tp";
$max_summary = 5;

function summary_page ($subject, $date, $summary, $article_id)
{
global $summary_template;
$t = new Template();
$t->set_file("SummaryPage", $summary_template);
$article_url = "article_".$article_id.".php";
$date = ($date);
$summary = nl2br($summary);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"article_url" => $article_url
));
$t->parse("Summary", "SummaryPage");
return $t->get_var("Summary");
}

function main_page ($subject, $date, $summary, $article_id, $body)
{
global $article_template;

$t = new Template();
$t->set_file("ArticlePage", $article_template);
$article_url = "article_".$article_id.".php";
$date =($date);
$summary =($summary);
$body =nl2br($body);
$t->set_var( array(
"subject" => $subject,
"date" => $date,
"summary" => $summary,
"body" => $body,
"article_url" => $article_url
));
$t->parse("Article", "ArticlePage");
return $t->get_var("Article");
}

function add_article($filename, $news)
{

if(file_exists($filename)){
$fh = fopen($filename, "r");
$old_news = fread($fh, filesize($filename));
fclose($fh);
}

/* TODO: Multipage articles
preg_match_all("<!--ARTICLE PAGE=(\d*)-->", $old_news, $matches;

if( count($matches[0]) >= $max_summary){
$oldfilename = $filename.($matches[0][0]+1);
}
*/

$fh = fopen($filename, "w");
$news = stripslashes($news);
fwrite($fh, "\n\n$news $old_news");
fclose($fh);
}

if(strcmp($subject, "")){
if(!(strcmp($passwd, $password))){
add_article("article_summary.php", summary_page($subject, $date,
$summary, $article_id));
add_article("article_$article_id.php", main_page($subject, $date,
$summary, $article_id, $body));
echo "<br><p><a href=article_$article_id.php>Article has been
added!</a></p>";
}else{
echo "<p><b> Password is wrong!</b></p>";
}
}
?>


<form action=news.php method=post>
<table border=0>
<tr> <td valign="top"><p class="header1">(Password):</p></td><td> <input
type=password name=passwd size=20> </td></tr>
<tr> <td valign="top"><p class="header1">Subject:</p></td><td> <input
type=text name=subject size=50> </td></tr>
<tr> <td valign="top"><p class="header1">Article ID:</p></td><td> <input
type=text name=article_id value=<? echo date("Y_m_j_is"); ?> size=30>
</td></tr>
<tr> <td valign="top"><p class="header1">Date/Author:</p></td><td> <textarea
name=date rows=2 cols=50 wrap=soft><? echo date("M j, Y\n"); ?>Author:
</textarea> </td></tr>
<tr> <td valign="top"><p class="header1">Summary:</p></td><td> <textarea
name=summary rows=5 cols=50 wrap=soft></textarea> </td></tr>
<tr> <td valign="top"><p class="header1">Body:</p></td><td> <textarea
name=body rows=15 cols=50></textarea> </td></tr>
</table><br>
<center><input type=submit name=submit value=Add-Article></center>
</form>

--
Cheap As Chips Broadband http://yeah.kick-butt.co.uk
Superb hosting & domain name deals http://host.kick-butt.co.uk
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h47.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16060 seconds with 13 queries