text: Q:
  
  how can mysql update its own data?
  
  I got a mysql database which contains some trading orders(sell orders and buy orders). I want mysql to run my code written in javascript or php to 'trade' the orders. For example, if I have one sell order that sells 5 items at a certain price and one buy order that buys 3 items at the same price, I want the buy order to be filled and 2 items left for sell.
  I can write code in html pages, so it trades every time when someone opens my url. However, I want it to keep trading on the server side no matter whether a users observes or not.
  
  Can mysql calculates its own data automatically? How can I set up the trading process on mysql?
  If 1 is not possible, can I write some javascript or php code and let mysql run my code automatically? How can I set it up?
  
  Can anyone help please? Thanks!
  
  A:
  
  Sure, you can have mechanism to make mysql to update its own data. 
  
  Using server side script and cron jobs, used mostly for scheduling some database job/scripts on server automatically or at intervals.  
  Using Cron jobs to execute PHP script?how to run php file using cron jobs
  http://www.thegeekstuff.com/2011/07/php-cron-job
  Using 'Triggers' in mysql database, used mostly for calculation or job if there is a event of change on particular table or data.
  http://www.sitepoint.com/how-to-create-mysql-triggers/ 
  
  