Re: split in to multiple pages (I think)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In news: CC.25.58774.9E80DE64@xxxxxxxxxxxx - 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 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux