JDKeller's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
17 (0.01 per day)
Joined:
13-May 10
Profile Views:
1,204
Last Active:
User is offline Jul 06 2013 10:28 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
XBox
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   JDKeller has not set their status

Posts I've Made

  1. In Topic: Web Based Game Essentials

    Posted 28 Jun 2012

    I want to address the issue of cron jobs on a server. If you are running a Linux environment or using a web host like Amazon, there is support for cronning tasks, however with Yahoo, there is no option. Here is how I do it using the UNIX timestamp and simple math.

    This is a function used to update energy based on time.
    function updateEnergy($userid){
     	// setup your db conection
    
    	$lastUpdatedQuery = sprintf("SELECT last_updated FROM energy WHERE userid = '%s'",
    		mysql_real_escape_string($userid));
            // last_updated is stored as an integer based on UNIX_Timestamp
    	$lastUpdatedResult = mysql_query($lastUpdatedQuery);
        $lastUpdatedRow = mysql_fetch_row($lastUpdatedResult);
    	$lastUpdated = $lastUpdatedRow[0];
    	$getCurrentEnergyQuery = sprintf("SELECT energy FROM energy WHERE userid = '%s'",
    		mysql_real_escape_string($userid));
    	$getCurrentEnergyResult = mysql_query($getCurrentEnergyQuery);
        $getCurrentEnergyRow = mysql_fetch_row($getCurrentEnergyResult);
    	$currentEnergy = $getCurrentEnergyRow[0];
    	
    	$ticks = (time() - $lastUpdated);
            // In PHP, time() returns the current time in seconds since the epoch.
    	// Ticks are the amount of time that has passed since the last update in seconds.
    	if ($ticks > 3600) {
            // 3600 seconds = 1 hour
    		if (intval($currentEnergy) >= 10){
                    // Since 10 is the maximum energy value, this just sets the update time to when it should have last updated.
    			$newUpdate = ($lastUpdated + (intval($ticks / 3600)*3600));
    			//mysql_query($updateEnergyQuery);
    			$updateLastUpdatedQuery = sprintf("UPDATE energy SET last_updated = " . $newUpdate . " WHERE userid = '%s'",
    				mysql_real_escape_string($userid));
    			mysql_query($updateLastUpdatedQuery);
    		} else {
    			$intNumberOfUpdates = (intval($ticks / 3600) + $currentEnergy);
    				if ($intNumberOfUpdates > 10) {
    					$updateEnergyQuery = sprintf("UPDATE energy SET energy = '10' WHERE userid = '%s'",
    						mysql_real_escape_string($userid));
    					mysql_query($updateEnergyQuery);
    				} else {
    					// how many times to update the table, or how much energy to update the table with.
    					$newUpdate = ($lastUpdated + (intval($ticks / 3600)*3600));
    					$updateEnergyQuery = sprintf("UPDATE energy SET energy = " . $intNumberOfUpdates . " WHERE userid = '%s'",
    						mysql_real_escape_string($userid));
    					mysql_query($updateEnergyQuery);
    				}
    			$updateLastUpdatedQuery = sprintf("UPDATE energy SET last_updated = " . $newUpdate . " WHERE userid = '%s'",
    				mysql_real_escape_string($userid));
    			mysql_query($updateLastUpdatedQuery);		
    			}
    		
    	} else {
    		// do nothing ...
    	}
    }
    


    What this does is update the table for energy value and last_updated time so that there will be a consistent record. I am sure this is lacking, but this is a good start.
  2. In Topic: i need help here,session not working in my code

    Posted 12 Jun 2012

    Rather, that is what variable will be returned.
  3. In Topic: i need help here,session not working in my code

    Posted 12 Jun 2012

    What are you expecting the variable to be? What should the array index be?

    Because you are using concatenation to define a variable, so what do you expect the variable to look like?

    $_SESSION['cart_'.$_GET['add']]+='1';
    
    // Will return $_SESSION['cart_1'] if $_GET['add'] = true
    // and $_SESSION['cart_0'] f $_GET['add'] = false
    
    
  4. In Topic: Trouble processing form data

    Posted 7 Jun 2012

    I understand, I just wanted to see if it worked or not.

    Happy hacking.
  5. In Topic: Trouble processing form data

    Posted 7 Jun 2012

    So, did the concatenation work?

My Information

Member Title:
New D.I.C Head
Age:
27 years old
Birthday:
September 28, 1986
Gender:
Interests:
Web-design and IT Security. Beginning Java.
Programming Languages:
HTML 4.01, XHTML, CSS, Java

Contact Information

E-mail:
Click here to e-mail me
Yahoo:
Yahoo  keller_joshua
Facebook:
http://www.facebook.com/CTRKeller

Friends

JDKeller hasn't added any friends yet.

Comments

JDKeller has no profile comments yet. Why not say hello?