Jump to content

[SOLVED] Simple MySQL counter


bundyxc

Recommended Posts

Here's my code:

 

DECLARE @today INTEGER
DECLARE @all INTEGER

UPDATE `users` SET
    `url` = 'turtle',
    `img` = 'images/nopic.png',
    (`todayLogins` = @today = @today + 1),
    (`allLogins` = @all = @all + 1),

WHERE `friendID` = '382009778'

 

I'm a total SQL noob, so here's my error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @today INTEGER DECLARE @all INTEGER UPDATE `users` SET `url` = 'turtle','

 

All I'm looking for is a code to create a simple counter, and apparently this isn't it. ;)

Can somebody point out what I'm doing wrong, or provide example code of something I can do better? Thanks for your time.

Link to comment
https://forums.phpfreaks.com/topic/169448-solved-simple-mysql-counter/
Share on other sites

The manual is a great place!

 

DECLARE is allowed only inside a BEGIN ... END compound statement and must be at its start' date=' before any other statements.[/quote']

 

Anyway, I don't get what you're trying to do.

 

Can't you just do like this?

UPDATE users SET allLogins = allLogins + 1 WHERE friendID = 123;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.