473,807 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't get $cnt++ to work


I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?
if(file_exists( "counter.da t")) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!
$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}

thanks,
Wilfred
Jul 17 '05 #1
20 3050
On Tue, 27 Jul 2004 19:01:36 -0400
Wilfred Johnson <wj****@yahoo.c om> wrote:

I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?


What happens if you replace $cnt++ with ++$cnt?

This might not work, just an idea...

Madsen

--
Anders K. Madsen --- http://lillesvin.linux.dk

"There are 10 types of people in the world.
Those who understand binary - and those who don't."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBBuZolNH Je/JASHcRAg2SAJ0eU/e3kidGrBoe92fbF lOxqSGsUACfeTRV
hRUEq2cil4if7QU 4iehQBt0=
=urf/
-----END PGP SIGNATURE-----

Jul 17 '05 #2
> I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?

$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!


Please use the following notation and your $cnt++ will work -
$cnt = (int) fread($f, 10);

_______________ _______________ ______
Wil Moore III, MCP | Integrations Specialist
Jul 17 '05 #3
On Tue, 27 Jul 2004 16:38:41 -0700
<la*******@hotm ail.com> wrote:
I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?

$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!


Please use the following notation and your $cnt++ will work -
$cnt = (int) fread($f, 10);


Oh yeah, of course!
Disregard my answer earlier in this thread, it sucks!

So much for PHPs implicit types! :-p

--
Anders K. Madsen --- http://lillesvin.linux.dk

"There are 10 types of people in the world.
Those who understand binary - and those who don't."

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBBuvIlNH Je/JASHcRAqhhAJoCv Da1zMjYauov1Lu8 iBjYQ3UUtQCfTfG Q
g5M7h2MZOaWscWa 1b/HEf6U=
=w7pP
-----END PGP SIGNATURE-----

Jul 17 '05 #4
Wilfred Johnson wrote:
I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?
if(file_exists( "counter.da t")) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!
$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}

thanks,
Wilfred

I put it on my server, it works fine:

<?
if(file_exists( "counter.da t")) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
$cnt++;
//$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}
?>

If that doesn't work, then you need to break the code up into simpler
steps to find out why.

start with:
<?
$cnt=8;
$cnt++;
echo $cnt;

?>
If it says "9", which would be correct, then there's probably something
wrong with your original code. Just reconstruct the original code a
piece at a time until the error reappears.

red
Jul 17 '05 #5

I did cast the fread return to an int and it now works now. My php
is on linux and is version 4.3.7.
On Wed, 28 Jul 2004 03:31:30 GMT, Rainbow News Service
<ne**@rainbowfa mily.info> wrote:
Wilfred Johnson wrote:
I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?
if(file_exists( "counter.da t")) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!
$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}

thanks,
Wilfred

I put it on my server, it works fine:

<?
if(file_exists ("counter.dat") ) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
$cnt++;
//$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}
?>

If that doesn't work, then you need to break the code up into simpler
steps to find out why.

start with:
<?
$cnt=8;
$cnt++;
echo $cnt;

?>
If it says "9", which would be correct, then there's probably something
wrong with your original code. Just reconstruct the original code a
piece at a time until the error reappears.

red


Jul 17 '05 #6
Anders K. Madsen wrote:

Could you check your news settings, Anders ? All your contributions appear
as attached files.
TY
Pjotr
Jul 17 '05 #7
On Wed, 28 Jul 2004 15:22:06 +0200, Pjotr Wedersteers wrote:
Anders K. Madsen wrote:

Could you check your news settings, Anders ? All your contributions appear
as attached files.
TY
Pjotr

They all appear fine to me...
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
I suspect the news issue is your client ;)

Regards,

Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #8
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 28 Jul 2004 15:22:06 +0200
"Pjotr Wedersteers" <x3****@westert erp.com> wrote:
Could you check your news settings, Anders ? All your contributions
appear as attached files.


Of course... I've heard complaints about this before, but alas, I don't
know what causes it.
I'm trying a new setting now, so if it's alright, please tell me so.

I'm using Sylpheed-Claws (as you can see in my X-Mailer header), so if
anyone knows how to make it _not_ attach the messages I'd be very
delighted to hear it.

Best regards
Madsen

- --
Anders K. Madsen --- http://lillesvin.linux.dk

"There are 10 types of people in the world.
Those who understand binary - and those who don't."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBB7GLlNH Je/JASHcRAta5AJ4py n5isgexxDNuoS2g Vj/8ciqsZwCdFfL1
A7YwDMaEgfFKKJu vbHgZjjE=
=bMzP
-----END PGP SIGNATURE-----
Jul 17 '05 #9
I think you may try that:

$cnt=trim($cnt) ;
$cnt++;
Wilfred Johnson <wj****@yahoo.c om> wrote in message news:<qh******* *************** **********@4ax. com>...
I have a little simple hit counter. It works if I replace $cnt++;
with #cnt = $cnt + 1;
I can't see why this doesn't work. Any ideas?
if(file_exists( "counter.da t")) {
$f = fopen("counter. dat", "r");
$cnt = fread($f, 10);
//echo "\n", "count 1 = ", $cnt, "\n";
fclose($f);
//$cnt++; DOESN'T WORK!!!
$cnt = $cnt + 1;
//echo "\n", "count 2 = ", $cnt, "\n";
$f = fopen("counter. dat", "w");
fwrite($f, $cnt);
fclose($f);
printf("\n%d people have visited this page\n", $cnt);
}

thanks,
Wilfred

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1909
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var decimalPointDelimiter = ".";
3
2526
by: Dean Slindee | last post by:
I want to build an array on the fly in code with a parameter passed for the number of elements in the array. I am trying to do this by looping, but get an array with just one element in the end. Can this be done my way or some other way? Dim idx As Integer Dim cnt As Integer = 5 'parm for # of elements Dim picArray As PictureBox()
6
1830
by: Paul Sullivan | last post by:
Hi folks. I was hoping that someone can help me out here. I am adding items to a listbox from a database. So far, I've had no problems. However, when I try to use the SetSelected method and there is only one item in the list box (who's index is 0), it won't highlight (or at least, it doesn't show it on the screen). Here my relevant code: ' Load Product List
1
2504
by: zxo102 | last post by:
Hi everyone, I need your help for using python odbc module. I have a simple table defined as create table A ( userId char(10), courseid char(10), grade integer, primary key(userId,courseId) )
4
1447
by: Schüle Daniel | last post by:
Hello group, >>> lst= >>> for i in range(10): .... lst.append(eval("lambda:%i" % i)) .... >>> lst() 0 >>> lst() 1
4
1766
by: jpenguin | last post by:
So I hope someone here can figure it out... main.cpp #include <iostream> #include <iomanip> #include "class.h" using namespace std; void Q(double, double, double, double); double nq(int);
2
1859
by: Msleh08 | last post by:
Hello. The code below shows a basic html text file with a highlighted bar that scrolls over each <tr> using your up/down arrow. If you notice, when you scroll using your up/down arrow the page jerks. How would I remove the jerking? Also, when the highlighted bar reaches close to the bottom it shows a few lines that are to come. Is there a way in Javascript that I show more lines after the higlighted bar? Thank you in advance for your help. :o) ...
9
6132
by: Dhiru1009 | last post by:
Hi guys, I am trying to build a user registration form using PHP and MYSQL but encountring a problem. When I click on submit with empty fields it adds records to database also it doesn't matter what information I put it always add records to database when I click on submit. What can I do to make sure user will not be able to add records to database until he enters the right information? I am posting my code for you guys to have a look...
7
10672
Walt in Decatur
by: Walt in Decatur | last post by:
I'm trying to use this method to copy an range in Excel workbook that is closed to the one that's open. I'm using the following code, which gets the "Can't find installable ISAM" error when I get to the line "cnt.Open". My Windows files (various .dll) are up to date, so there is some other hitch in there. Sub Get_Data_Closed_Workbooks() Dim cnt As ADODB.Connection Dim cmd As ADODB.Command Dim stCon As String, stSQL As String...
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.