Home | The PHP Group | PHP | Php counter
The PHP Group PHP
Problem for The PHP Group PHP

Php counter




By d_howley on Mar 19, 2009

" "
im trying to add a visitor counter to my homepage i downloaded the script but not sure what to do and where to put things to get it running this is the counter script...
// Connect to server and select database.
mysql_connect(''$host'', ''$username'', ''$password'')or die(''cannot connect to server '');
mysql_select_db(''$db_name'')or die(''cannot select DB'')
$tbl_name=''counter''; // Table name
$sql=''SELECT * FROM $tbl_name'';
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$counter=$rows['counter'];
// if have no counter value set counter = 1
if(empty($counter)){
$counter=1;
$sql1=''INSERT INTO $tbl_name(counter) VALUES('$counter')'';
$result1=mysql_query($sql1);
}
echo ''You 're visitors No.''
echo $counter;
// count more value
$addcounter=$counter+1;
$sql2=''update $tbl_name set counter='$addcounter''';
$result2=mysql_query($sql2);
mysql_close();
?>

and this is mode homepage code..
<table id=''tablelayout''>
<tr>
<td><table id=''tableNav'' >
<tr>
<td><img src=''images/logo.gif'' width=''350'' height=''117'' /></td>
<td valign=''bottom''><a href=''index.php''><img src=''images/smallbutton1.gif'' width=''92'' height=''30'' border=''0'' /></a></td>
<td valign=''bottom''><a href=''phpdenora/index.php''><img src=''images/smallbutton2.gif'' width=''92'' height=''30'' border=''0'' /></a></td>
<td valign=''bottom''><a href=''irpg/index.php''><img src=''images/smallbutton3.gif'' width=''92'' height=''30'' border=''0'' /></a></td>
<td valign=''bottom''><a href=''forum_system/main_forum.php''><img src=''images/smallbutton4.gif'' width=''92'' height=''30'' border=''0'' /></a></td>
</tr>
</table>
<table width=''95%'' align=''center'' cellspacing=''3'' id=''loginbar''>
<tr>
<td align=''right''><a href=''login_system/main_login.php''>LOGIN</a></td>
</tr>
</table></td>
</tr>
<tr>
<td id=''tdTableCenter''><table id=''mainButtons'' >
<tr>
<td id=''tdtopButton''><a href=''phpdenora/index.php''><img src=''images/bigbutton1.gif'' width=''167'' height=''36'' border=''0'' /></a></td>
<td id=''topButtonRight''><p>Wanna find out all the latest upto date infomation<br />
on the AbZoRbeD network, Then check this out.</p>
</td>
</tr>
<tr>
<td id=''tdbottomButton''><a href=''irpg/index.php''><img src=''images/bigbutton2.gif'' width=''167'' height=''36'' border=''0'' /></a></td>
<td id=''topButtonBottom''><p>Dont idle for no reason join in the game and have<br />
a little fun battling against the other players.</p>
</td>
</tr>
<tr>
<td id=''tdbottomButton''><a href=''forum_system/main_forum.php''><img src=''images/bigbutton3.gif'' width=''167'' height=''36'' border=''0'' /></a></td>
<td id=''topButtonBottom''><p>Use this forum for discussing all kinds of <br />
topics you must be registered and logged<br />
in to access this area if you would like<br />
to register <a href=''login_system/insert.php''>Click Here</a> </p></td>
</tr>
</table></td>
</tr>
<tr>
<td><table id=''tableFooter'' >
<tr>
<td id=''tdFooterLeft''>&nbsp;</td>
<td id=''tdFooterCenter''><p class=''style1''><a href=''contactus/contactus.htm''>Contact Us</a><br />
&copy; AbZoRbeD.net 2007-2009</p>
</td>
<td id=''tdFooterRight''></td>
</tr>
</table></td>
</tr>
</table>
any help would be grate :)
Comments:

Mar 19, 2009

- sorry i forgot to say that i have that all setup
just didnt want my username and password getting out :)

Mar 20, 2009

- should the path to the counter.php go in here <?php counter(IN HERE); ?></td> i got the counter.php in a folder called counter because i keep getting the error ... PHP Fatal error: Call to undefined function counter()

Mar 20, 2009

- i did what you said now im just getting an error .... Fatal error: Call to undefined function counter()

Best Solution

posted on May 09, 2009
Very Helpful)

will_00

Rank: Apprentice 
Rating: 95%, 2 votes
You might want to note that this is not the most effective manner of creating a counter in PHP. On a few of my websites, I find it is much more effective to simply create a text file, eg. counter.txt and have PHP read that every time the page is loaded, instead of running a MySQL query. Then, have PHP also update the counter.txt file by adding 1 to the number already listed in the file and read to the user.
Was this helpful?
Yes
No
1 person thought this was helpful

Solution #2

posted on Mar 19, 2009
Not Rated)

Dubravko

Rank: Master 
Rating: 0%, 0 votes
These lines

mysql_connect(''$host'', ''$username'', ''$password'')or die(''cannot connect to server '');
mysql_select_db(''$db_name'')or die(''cannot select DB'')
$tbl_name=''counter''; // Table name
$sql=''SELECT * FROM $tbl_name'';

say that you need mysql database. user name, password and table in that database called counter....

So if you do please change parameters if you don't, dont yuse this script, use just some site with free simple counter for your site, which is maintained on their site

Comments:

Mar 19, 2009

- Then, the best way is to wrap it into some function, include that code in homepage and call function from somewhere in page where you want it to be seen , for ex.

<?php
function counter()
{
//copy counter code here
}
?>.....
<td id=''tdFooterRight''>
<?php counter(); ?></td>

....


Mar 20, 2009

- See this page for includes, don't change function call.

http://www.w3schools.com/PHP/php_includes.asp

in your case
<?php include("counter\counter.php"); ?>

Was this helpful?
Yes
No

Popular Solutions for The PHP Group PHP


Questions and Unsolved Problems for The PHP Group PHP


Do you recommend The PHP Group PHP?
Answer

Answer
I want to execute java command for a software which is stored on my web server with the help of... (More)

Answer
subject avaluation system php w/ mysql codes how to evaluate subject using php w/ mysql

Answer
Hi there, I am using PHP5, where i need to mail with attachement. exact thing is, am getting the... (More)

Answer
Hiya Im trying to get a collaspable panel to save state, the example I am currently using is... (More)


Didn't find what you were looking for?

Describe your problem:

Select a Category:





Sponsored Links



Ask our Experts

 

Solve Your Problem Now!
Chat Live with an Expert
Chat Now
Browse popular Problems
More Common Problems
Most Common Problems for:
For The PHP Group PHP:

Top Programming Tool Experts

Rank: Guru Guru  

Solutions: 418
Member Since: October 2009

Experience: Experienced a lot in computer troubleshooting. Knowledgeable about cellular phones.

Ask Me
Find more Programming Tool Experts

Top Computer & Laptop Repair

(877) 729-0812
We connect to your computer over the Internet to...
Remote Repair

(952) 890-7770
Zkarlo.com provides discount and used laptop parts...
Zkarlo.com


       
Solve Your Problem Now!
Chat Live with an Expert
Chat Now

X
Continue
When the original poster rates a solution that was given to his own problem, that rating is locked!
X

Are you sure the solution content is Inappropriate?
   
Tech buddies can communicate directly to answer questions. Become a Tech Buddy and have direct access to your favorite expert for FREE!
Insert Link
Insert Image
Insert You-Tube clip
Insert List
Insert List
Spell Check

What is this?



Select