big fan of the site, I was just wondering if anyone can lend a hand in this code that i have. It works but it is terrible. I know that there is a much easier way.
BTW this is one of the first pieces of code that i have ran after looking at halls tutorials. But I am sure that you can tell by the code itself
Code: Select all
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)){
echo "Name: " . $row['name'] . " - Time " . gmdate("H:i:s", $row['time']) . "<a href='index.php?id=$row[id]&time=$row[time]'>Begin quest</a><br>";
echo "<br>" . time();
}}else {
echo "0 results";
}}
Code: Select all
if (isset($_GET['time'])){
$id=$_GET['id'];
$time = $_GET['time'];
$remaining = $time + time();
$updateplayer="update players set quest='$id' where name='player1'";
mysqli_query($db , $updateplayer) or die("Could not update player");
$updateplayer2="update players set questt='$remaining' where name='player1'";
mysqli_query($db , $updateplayer2) or die("Could not update player");
echo "Quest started";
}
if ($playerinfo3['questt'] > 1){
if (time() >= $playerinfo3['questt']){
$updateplayer2="update players set questt='0' where name='player1'";
mysqli_query($db , $updateplayer2) or die("Could not update player");
}else{
echo "You are already in a quest! come back after you have completed your current quest";
echo "<br>" . time();
}}
this is the code in question, basically it does a check to see if the questt(quest time is greater than 0) if so then it says that you cannot do another quest until the current one if finished. (again this works but needs to be improved)
The worst part is the way that I implement time again it works but it is terrible. it adds the quest length which is 500 seconds to cron time and then checks if cron time is greater or equal to the quest length before resetting the questt to 0.
Thank you for you help