Location: PHPKode > projects > Babylon 5: Upheaval > b5-upheaval/tick.php
<!--    

	Copyright 2007 Martin Remisch

	This file is part of "Babylon 5: Upheaval".

    "Babylon 5: Upheaval" is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as published 
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Babylon 5: Upheaval" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Babylon 5: Upheaval".  If not, see <http://www.gnu.org/licenses/>.

 -->


<?php

	session_start();
	error_reporting(E_ALL);
	include('db_include.inc');	

	mysql_connect(HOST,USER,PASS)or die(mysql_error());
	mysql_select_db(DATABASE) or die(mysql_error());

	$count = 0;
	$names = array();

	if(($resResource = mysql_query('SELECT name FROM users')))
	{
		while($line = mysql_fetch_assoc($resResource))
		{

			unset($current_name);
			$current_name  = $line['name'];
			$names[$count] = $line['name'];
			$current_db 	= "planeten_".$current_name;
			$current_time  = time();
	
		
			$nr_planets = mysql_result(mysql_query("SELECT count(id) FROM $current_db"),0);

			for ($k=1; $k <= $nr_planets[0];$k++)
			{

				$row = mysql_fetch_array(mysql_query("SELECT * FROM $current_db WHERE id='$k'"),MYSQL_NUM);

				for ($l=16;$l <= count($row);$l+=3)
				{
					$old_status 	 = mysql_fetch_array(mysql_query("SELECT * FROM $current_db"),MYSQL_NUM);
					$coulumn_names  = mysql_query("SELECT * FROM $current_db");
					$countdown_time = mysql_fetch_array(mysql_query("SELECT ".mysql_field_name($coulumn_names,$l)." FROM $current_db WHERE ".mysql_field_name($coulumn_names,$l)." <> '-1'"));

					if (!empty($countdown_time[0]) AND $countdown_time[0] < $current_time)
					{
						mysql_query("UPDATE $current_db SET ".mysql_field_name($coulumn_names,$l)."='-1',".mysql_field_name($coulumn_names,($l-2))."='".(($old_status[$l-2])+1)."'");
					}

				}

			}
			$count++;

      }

	}

?>
Return current item: Babylon 5: Upheaval