Help with cron, database

Discussion in 'Databases' started by starsi, Apr 24, 2009.

  1. #1
    Need help with cron - database coding.

    I'm trying to set up a cron on a game site of mine. The game updates the energy, health and income of the user.

    One of them is working, updating the user's health and energy, but somehow the income doesn't update.

    I used the advanced unix with the following cron code:

    env php -q /home/USERNAME/public_html/fightclub/cron/usercashcron.php


    Here's the usercashcron.php file

    <?php

    include "../includes/config.php";

    //====================================
    // Get User Income
    //====================================
    function get_income( $id ) {
    $res = query("SELECT * FROM `cu_assest_list` WHERE `aid`=$id");
    while( $row = mysql_fetch_array($res) ) {
    $income = $row[aincome];
    }
    return $income;
    }

    //====================================
    // Update User Cash
    //====================================
    function update_cash( $u ) {

    $total_cash = 0;

    $res = query("SELECT * FROM `cu_assest_log` WHERE `userid`=$u");
    while( $row = mysql_fetch_array($res) ) {
    $total_cash = $total_cash + ( $row[quantity] * get_income($row[aid]) );
    }

    $res = query("UPDATE `cu_users` SET `ucash`=(`ucash`+ $total_cash) WHERE `userid`=$u");

    }

    ?>
     
    starsi, Apr 24, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    u need to instantiate the functions and provide userid
    
    <?php
    
    include "../includes/config.php";
    
    //====================================
    // Get User Income
    //====================================
    function get_income( $id ) {
    $res = query("SELECT * FROM `cu_assest_list` WHERE `aid`=$id");
    while( $row = mysql_fetch_array($res) ) {
    $income = $row[aincome];
    }
    return $income;
    }
    
    //====================================
    // Update User Cash
    //====================================
    function update_cash( $u ) {
    
    $total_cash = 0;
    
    $res = query("SELECT * FROM `cu_assest_log` WHERE `userid`=$u");
    while( $row = mysql_fetch_array($res) ) {
    $total_cash = $total_cash + ( $row[quantity] * get_income($row[aid]) );
    }
    return $total_cash;
    }
    
    $u = 'youruserIDhere';
    $total_cash = update_cash($u);
    $res = query("UPDATE `cu_users` SET `ucash`=(`ucash`+ $total_cash) WHERE `userid`=$u");
    
    
    
    ?>
    
    PHP:
     
    crivion, Apr 25, 2009 IP
  3. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Maybe there's some error with the cron command.

    In the past I tried php -l to call a .php file, but it does not work as expected. Then I used lynx its URL and all works :)

    Or, you can try a external cron jobs (onlinecronjob.com www.setcronjob.com) to call your URL instead of lynx (if your host doesn't have lynx)
     
    thuankkk, Apr 26, 2009 IP