<?php
include("db.php");
$sql = "SELECT town_id, holz, eisen, stein, lehm, mana, time FROM village WHERE town_id = '".$_GET['town_id']."' ";
$result = mysql_query($sql) OR die(mysql_error()." => ".mysql_errno());
$rows = mysql_fetch_assoc($result); {
$timestamp_db = $rows['time'];
$holz = $rows['holz'];
$eisen = $rows['eisen'];
$stein = $rows['stein'];
$lehm = $rows['lehm'];
$mana = $rows['mana'];
mysql_close();
}
$sql2 = "SELECT town_id, holzfaeller, eisenmiene, steinbruch, lehmgrube, magiergilde FROM village_stufe WHERE town_id = '".$_GET['town_id']."' ";
$result2 = mysql_query($sql2) OR die(mysql_error()." => ".mysql_errno());
$rows2 = mysql_fetch_assoc($result2);{
$holzst = $rows2['holzfaeller'];
$eisenst = $rows2['eisenmiene'];
$steinst = $rows2['steinbruch'];
$lehmst = $rows2['lehmgrube'];
$manast = $rows2['magiergilde'];
mysql_close();
}
$sql3 = "SELECT id, holz FROM produktion WHERE holz = '$holzst' ";
$result3 = mysql_query($sql3) OR die(mysql_error()." => ".mysql_errno());
$rows3 = mysql_fetch_assoc($result3);{
$wert_holz = $rows3['holz'];
}
$sql4 = "SELECT id, eisen FROM produktion WHERE eisen = '$eisenst' ";
$result4 = mysql_query($sql4) OR die(mysql_error()." => ".mysql_errno());
$rows4 = mysql_fetch_assoc($result4);{
$wert_eisen = $rows4['eisen'];
}
$sql5 = "SELECT id, stein FROM produktion WHERE stein = '$steins' ";
$result5 = mysql_query($sql5) OR die(mysql_error()." => ".mysql_errno());
$rows5 = mysql_fetch_assoc($result5);{
$wert_stein = $rows5['stein'];
}
$sql6 = "SELECT id, lehm FROM produktion WHERE lehm = '$lehmnst' ";
$result6 = mysql_query($sql6) OR die(mysql_error()." => ".mysql_errno());
$rows6 = mysql_fetch_assoc($result6);{
$wert_lehm = $rows6['lehm'];
}
$sql7 = "SELECT id, mana FROM produktion WHERE mana = '$manast' ";
$result7 = mysql_query($sql7) OR die(mysql_error()." => ".mysql_errno());
$rows7 = mysql_fetch_assoc($result7);{
$wert_mana = $rows7['mana'];
}
mysql_close();
$timestamp = time(); // $timestamp ist die aktuelle Serverzeit in sek gespeichert
$diff_zeit = $timestamp - $timestamp_db ; // ermittelt die vergangene zeit in sek
$holz_neu = $holz + (diff_zeit * wert_holz);
$eisen_neu = $eisen + (diff_zeit * wert_eisen);
$stein_neu = $stein + (diff_zeit * wert_stein);
$lehm_neu = $lehm + (diff_zeit * wert_lehm);
$mana_neu = $mana + (diff_zeit * wert_mana);
mysql_query("UPDATE village SET holz = '$holz_neu', eisen = '$eisen_neu', stein = '$stein_neu', lehm = '$lehm_neu', mana = '$mana_neu', time = '$timestamp'
WHERE holz = '$holz', eisen = '$eisen', stein = '$stein', lehm = '$lehm', mana = '$mana', time = '$timestamp_db'")
OR die(mysql_error());
mysql_close();
?>