Simple PHP code edit? Add a function for me.

Discussion in 'Programming' started by Cobrabid, Dec 5, 2008.

  1. #1
    Hi I have a script that manages some articles.
    The script shows the last 3 articles using the following code:

    In config file:

    $max_latest = 3;

    And in another file:

    <?

    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;
    }
    }
    }

    ?>


    My question is:
    How do I get it to ONLY show articles 4-8??? Is there a simple code to add? Can you write that code for me? whats the price??
    Thx
    t
     
    Cobrabid, Dec 5, 2008 IP
  2. mac83

    mac83 Active Member

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    $articles = explode("<!--ARTICLE-->", $old_news);
    $countarticles = count($articles);



    if ($countarticles >= 4) {

    if ($countarticles > = 8) {
    $lastarticle = 8;
    } else {
    $lastarticle = $countarticles;
    }

    for ($i=3; $i<=$lastarticle; $i++) {
    print $article[$i];
    }
    }
     
    mac83, Dec 5, 2008 IP
  3. Cobrabid

    Cobrabid Guest

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Hey!
    Thanks mate! That was quick!
    Im to dum to get that to work.. I get a foult on line 9.. should I add something to the config file too?
    How about I send the files over to you and you add it in there nicely, and I pay you with paypal :) Drop me a PM.
    Thx again for your time.
    T
     
    Cobrabid, Dec 5, 2008 IP
  4. mac83

    mac83 Active Member

    Messages:
    237
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    
    <?php
    $filename = "article_summary.html";
    
    #- open article summaries
    if(file_exists($filename)){
    $fh = fopen($filename, "r");
    $old_news = fread($fh, filesize($filename));
    fclose($fh);
    }
    
    
    $articles = explode("<!--ARTICLE-->", $old_news);
    $countarticles = count($articles);
    
    if ($countarticles >= 4) {
    
    	if ($countarticles >= 8) {
    		$lastarticle = 8;
    	} else {
    		$lastarticle = $countarticles;
    	}
    
    	// If 	"<!--ARTICLE--> is present at the top of the article, then make $i=4 in the below line
    	for ($i=3; $i<=$lastarticle; $i++) {
    		print $articles[$i];
    	}
    }
    
    ?>
    
    
    PHP:
    This will work!
     
    mac83, Dec 5, 2008 IP