0

Good evening,

I've been searching around about the mysql event scheduler. Info and examples found on the web are very simple (and I have to admit my mysql experience is quite poor).

I need to do a mysql event scheduler that runs every hour. The event by itself isn't the problem. The thing is, I need the event to read a value from a field in each of the rows of the table, and then sum that value to another field of the row. Notice that this has to be done in all of the rows of the table, in a dinamic way, since the database keeps growing and I don't know how many rows I've got.

In PHP this would easy be to do with some for loops, a few arrays, then some UPDATE to mysql, and we would be done. The problem is that mysql event scheduler only works with mysql syntax, so this makes things a bit dificult.

I've got a table called users, it has some fields: id, name, economicalincome, credits, etc...

So.. For each id, the event should some the value from the economicalincome to the existent credits.

Thanks in advance.

Saguim
  • 20
  • 3
  • so, would you like to hire someone to fix this problem, or have you tried something or read relevant documentation? – serakfalcon Jun 21 '14 at 23:55
  • I actually tried this links, but it didn't solved my problem, make the event call a PHP script seems like a good idea, but it's not a good practice, so I'm out of solutions. http://stackoverflow.com/questions/5125096/for-loop-example-in-mysql http://stackoverflow.com/questions/10923300/mysql-event-scheduler-delimiter-using-php?rq=1 http://www.9lessons.info/2012/10/mysql-event-scheduler.html http://www.cs.duke.edu/csl/docs/mysql-refman/events.html – Saguim Jun 21 '14 at 23:57
  • Anyway, it seems that mysql doesn't even uses arrays, so it's dificult for someone with poor mysql experience to solve this. Maybe some one else did it, and can give some info on how to do it. – Saguim Jun 22 '14 at 00:02
  • it's hard to tell what you're trying to do exactly, what fields need to be summed where? – serakfalcon Jun 22 '14 at 00:02
  • I just edited, so try to be more specific, thanks for looking at it. – Saguim Jun 22 '14 at 00:07
  • so, basically you want to do `UPDATE users SET credits = credits + economicalincome;` or is there a catch? – serakfalcon Jun 22 '14 at 00:09
  • yap that's it, the thing is how do i do it for all the existent users, i don't have a for loop, not either one array with mysql_fetch_array result i could travel for by each user id, and update it. – Saguim Jun 22 '14 at 00:12
  • but that query will do it for every user in the database, that's how the query works. it only is restricted by the `WHERE` statement – serakfalcon Jun 22 '14 at 00:13
  • Ok..... Now that was simple. I told you mysql knowledge was poor. Djee, I didn't knew, that it was this poor. eheheheh, thanks man, you solved my problem then :) – Saguim Jun 22 '14 at 00:17

0 Answers0