User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,528 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,768 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 486 | Replies: 1
Reply
Join Date: Oct 2005
Location: Harare, Zimbabwe
Posts: 34
Reputation: tirivamwe is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
tirivamwe's Avatar
tirivamwe tirivamwe is offline Offline
Light Poster

Help problem with counter

  #1  
Oct 5th, 2007
i have this code which is supposed to increment a counter on page


   <?php  
 

//create a file called counter.txt and upload it to your server
//now open the file
$fp = fopen("counter.txt" , "r");
//read in the current count
$count = (int)fread($fp, 1024);
//increment the count by 1
$count++;
//close the file
fclose($fp);
//image display, get the lentgth of the count





echo"<table cellspacing=0 width =4% cellpadding=0 row=1 column=".strlen($count);
echo"<tr>";
for ($i = 0 ;$i < strlen($count) ; $i++)
{
$imgsrc = substr($count,$i ,1);
//display the image(s) note our images are in a folder located at
//images/count1/ change this to your location
echo"<td width=2%>";
echo "<img src =\"images/count1/" . $imgsrc . ".gif\">";
echo"</td>";
}
echo"</tr>";
echo"</table>";


//open the counter file
$fp = fopen("counter.txt", "w");
//write the new count to the file
fwrite($fp, $count);
//close the file
fclose($fp);
//include("grcounter.php"); 

 ?>

it is reading from text file and display the value from file but it is failing to update the file with the new value which is an increment of the counter
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: problem with counter

  #2  
Oct 5th, 2007
try this:

<?php
$open = fopen('counter.txt', 'r');
$read = fread($open, filesize('counter.txt'));
fclose($open);
$count = $read + 1;
$open = fopen('counter.txt', 'w');
$write = fwrite($open, $count);
fclose($open);

echo"<table cellspacing=0 width =4% cellpadding=0 row=1 column=".strlen($count);
echo"<tr>";
for ($i = 0 ;$i < strlen($count) ; $i++)
{
$imgsrc = substr($read,$i ,1);
//display the image(s) note our images are in a folder located at
//images/count1/ change this to your location
echo"<td width=2%>";
echo "<img src =\"images/count1/" . $imgsrc . ".gif\">";
echo"</td>";
}
echo"</tr>";
echo"</table>";
?>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC