Function based counter from the wrox book

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
frih
Forum Newbie
Posts: 1
Joined: Tue Mar 03, 2009 10:28 am

Function based counter from the wrox book

Post by frih »

This is the question from the book "Beginning PHP5,Apache,MYsql web development.

Question fro chapter-2 exercise

ques--> "Using functions, write a program that keeps track of how many times a visitor has loaded the page."

In the book, they have written--> //list the movies
echo “<table>”;
$numlist = 1;
while ($numlist <= $_POST[“num”]) {
echo “<tr>”;
echo “<td>”;
echo pos($favmovies);
echo “</td”>;
next($favmovies);
$numlist = $numlist + 1;
echo “</tr>”;
}
echo “</table>”;



But i don't think this is the answer because it just putting the movie result inside a table.




I have written one program myself for this question but it is not working correctly.

Here it is-->
<?php
echo " hello welcome here";
$counter1=0;
$counter;
function counter()
{
global $counter1,$counter;

$counter1++;
echo "you have visited this page for ".$counter1;
$counter=$counter1;
}
$counter=$counter1;
counter();
?>


Need help...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Function based counter from the wrox book

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Post Reply