The concept of my game relies on the fact that if you do not log in to take care of your pet, the pet will 'die'. Currently this is my code to measure the time past and to apply the negative modifiers to the pet's mood, hunger, and cleanliness levels.
$mod=mysqli_query($con,"select * from users where user_name='$user_name'");
while($row=mysqli_fetch_array($mod)){
$last_login=$row['last_login'];
$stored_login=$row['stored_login'];
$unixtime = (strtotime($last_login)-strtotime($stored_login));
//echo $unixtime;
$days = ($unixtime/60/12/24);
//echo $days;
$time_mod = mysqli_query($con,"update users set time_mod='$days' where user_name='$user_name'");
}
$pet=mysqli_query($con,"select time_mod from users where user_name='$user_name'");
$day1=1;
$day2=2;
$day3=3;
if($pet=$day1){
$pet_mod = mysqli_query($con,"select * from user_pet where user_name='$user_name'");
while($row=mysqli_fetch_array($pet_mod)){
$m1=$row['mood_level'];
$m2=$row['hunger_level'];
$m3=$row['cleanliness_level'];
$mm1=($m1-20);
$mm2=($m2-20);
$mm3=($m3-20);
$modm1="UPDATE user_pet SET mood_level='$mm1' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm1);
$modm2="UPDATE user_pet SET hunger_level='$mm2' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm2);
$modm3="UPDATE user_pet SET cleanliness_level='$mm3' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm3);
}
}
if($pet=$day2){
$pet_mod = mysqli_query($con,"select * from user_pet where user_name='$user_name'");
while($row=mysqli_fetch_array($pet_mod)){
$m1=$row['mood_level'];
$m2=$row['hunger_level'];
$m3=$row['cleanliness_level'];
$mm1=($m1-40);
$mm2=($m2-40);
$mm3=($m3-40);
$modm1="UPDATE user_pet SET mood_level='$mm1' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm1);
$modm2="UPDATE user_pet SET hunger_level='$mm2' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm2);
$modm3="UPDATE user_pet SET cleanliness_level='$mm3' WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm3);
}
}
if($pet>=$day3){
$pet_mod = mysqli_query($con,"select * from user_pet where user_name='$user_name'");
while($row=mysqli_fetch_array($pet_mod)){
$m1=$row['mood_level'];
$m2=$row['hunger_level'];
$m3=$row['cleanliness_level'];
$modm1="UPDATE user_pet SET mood_level=0 WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm1);
$modm2="UPDATE user_pet SET hunger_level=0 WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm2);
$modm3="UPDATE user_pet SET cleanliness_level=0 WHERE user_name = '$user_name'";
$q5=mysqli_query($con,$modm3);
}
}
I also have a picture that is supposed to change if your pet is 'dead' or not.
<?php
$account_r2 = mysqli_query($con,"SELECT * FROM user_pet WHERE user_name='$user_name'");
while($row = mysqli_fetch_array($account_r2)) {
$m1=$row['mood_level'];
$m2=$row['hunger_level'];
$m3=$row['cleanliness_level'];
if($m1=0){
echo "<img src='My Pet Monster-02.png' alt='Your Monster'>";
}
if($m2=0){
echo "<img src='My Pet Monster-02.png' alt='Your Monster'>";
}
if($m3=0){
echo "<img src='My Pet Monster-02.png' alt='Your Monster'>";
}
else{
echo "<img src='My Pet Monster-03.png' alt='Your Monster'>";
}
}
?>
However, if the time past is greateror equal to 1 my code is making the pet's mood equal to zero(which should only happen if it's greater than or equal to 3), and if any level is equal to 0 it is still not changing the picture. The time is storing correctly- any idea why the other code isn't working? Any advice or help is greatly appreciated!