Re: Counters :: Double, Triple :: What The Hell
| From: | vins | Date: | Fri, 19 Jul 2002 21:29:26 +0000 |
| Subject: | Re: Counters :: Double, Triple :: What The Hell | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108582@lists.php.net to get a copy of this message | ||
Shit...
Nice trick..
works great...
I really didn't know you could do that with mysql
but i always say.... "you learn everyday"
Another thing i didn't mention is that this dam counter increases on every
single page....
even when i'v only called it on the index.php page.
strange
"Wouter Van Vliet" <wouter@springt.nl> wrote in message
news:CPEAJACGLADEOMKBJJLNKEHBDBAA.wouter@springt.nl...
> Why do you first use the select? Since you don't return anything, you may
as
> well want to do:
> ---
> function countIt($action, $counter) {
> if ($action == "more") { $sign = "+"; };
> if ($action == "less") { $sign = "-"; };
> mysql_query("UPDATE counters SET $counter = $counter $sign 1");
> };
> ----
> this saves you a database query .. and well, it may also work around your
> problem. I think it shud .. Though I can't see where the error's hidden in
> your version ...
>
> Greetz,
> Wouter
>
> ----------
> Alle door mij verzonden email is careware. Dit houdt in dat het alleen
> herlezen en bewaard mag worden als je goed omgaat met al het leven op
aarde
> en daar buiten. Als je het hier niet mee eens bent dien je mijn mailtje
> binnen 24 uur terug te sturen, met opgaaf van reden van onenigheid.
>
> All email sent by me is careware. This means that it can only be reread
and
> kept if you are good for all the life here on earth and beyond. If you
don't
> agree to these terms, you should return this email in no more than 24
hours
> stating the reason of disagreement.
>
>
> -----Oorspronkelijk bericht-----
> Van: vins [mailto:vins@webonline.co.za]
> Verzonden: vrijdag 19 juli 2002 22:42
> Aan: php-general@lists.php.net
> Onderwerp: [PHP] Counters :: Double, Triple :: What The Hell
>
>
> Function CountIt($action, $counter)
> {
> $sql = "SELECT ".$counter." FROM counters WHERE id='1'";
> $res = mysql_query($sql);
> $num = mysql_result($res, 0, $counter);
>
> if($action == "more") $num++;
> if($action == "less") $num--;
>
> $sql = "UPDATE counters SET ".$counter."='".$num."' WHERE
> id='1'";
> $res = mysql_query($sql);
> }
>
> That is my script....
> I call it CountIt('more','hits');
>
> but everytime i call it, the dam thing always adds 2 counts
>
> Can anyone identify an error
>
> please
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>