Jump to content

[SOLVED] Function problem ?


nesiak

Recommended Posts

Hello there, i'm new to this forum as i am new to PHP!

 

This is my code that will output the number of comments and number of posts in a blog i'm trying to create. It doesn't output anything why?

 

<?php
function nofcom() 
{
$filee = fopen("comments.php", "r") or exit("Can't open comments file");
//Comments are all one line in height
while(!feof($filee))
  {
  fgets($filee);
  $i++;
  }
fclose($filee);
$nofcom == $i;
echo "Total comments : $nofcom .";
}

function nofart()
{
$filew = fopen("posts.php", "r") or exit("Can't open news file !");
//A star (*) is marking a beggining of a another post 
while(!feof($filew))
  {
  fgetc($filew); 
  if (fgetc($filew)=="*")
{
  $o++;
}  
}
fclose($filew);
$nofcom == $i;
echo "Ukupno komentara : $nofcom .";
}
?>

 

Please help

Link to comment
Share on other sites

noup still doesn't output anything ?

 

(i'm using this with include() maybe i'm using it wrong?)

 

<p class="style2"><?php include("status.php") ?></p>

 

There was a another error in my posted code, fixed it too and still it won't output anything to the page ?

 

<?php
function nofcom() 
{
$filee = fopen("comments.php", "are") or exit("Can't open comments file");
//Comments are all one line in height
while(!feof($filee))
  {
  fgets($filee);
  $i++;
  }
fclose($filee);
$nofcom = $i;
echo "Total comments : $nofcom .";
}

function nofart()
{
$filew = fopen("posts.php", "are") or exit("Can't open news file !");
//A star (*) is marking a beggining of a another post 
while(!feof($filew))
  {
  fgetc($filew); 
  if (fgetc($filew)=="*")
{
  $o++;
}  
}
fclose($filew);
$nofart = $o;
echo "Total articles : $nofcom .";
}
?>

Link to comment
Share on other sites

I dont see you actually call these functions anywhere. Function dont run by themselves, they need to be called. eg;

 

<?php

  function foo() {
    echo "this is foo";
  }

  // call the function.
  foo();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.