Forum Moderators: coopster

Message Too Old, No Replies

Simple Update Problem

         

inveni0

5:09 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



I'm trying to update a record each time a page is loaded...like a hit counter... I had it right once, but I accidentaly copied over that file with an older version. Now I'm trying to figure it out again. I'm using:

UPDATE ListInns SET counter=$NewCount WHERE BnBKey=$row_ListInns['BnBKey'];

Is there anything wrong with that? My page will not load when I use it. I just can't remember how I did it before.

I've also tried:

mysql_query("UPDATE ListInns SET counter=($OldCount + 1) WHERE BnBKey=$row_ListInns['BnBKey']");

dreamcatcher

5:30 pm on Mar 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

UPDATE ListInns SET counter=(counter+1) WHERE BnBKey = '".$row_ListInns['BnBKey'].'";

dc

inveni0

5:36 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



Yeah, I just came back to say that I worked it out. I needed to enclose the end of my WHERE clause in 's

I used:

// Update Hit count
$OldCount = $row_ListInns['counter'];
$BnBKey = $row_ListInns['BnBKey'];
$NewCount = $OldCount + 1;
if (!session_is_registered("counted")){
mysql_query("UPDATE BnBData SET counter=$NewCount WHERE BnBKey='$BnBKey'") or die(mysql_error());
session_register("counted");
}

Habtom

6:36 pm on Mar 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I prefer dreamcatcher suggestions. It is good to increment it there itself than to add to a variable and get the value back.

Habtom

inveni0

6:37 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



What's the difference as far as advantages (besides one less line of code.