Reputation: 1
I want to disbale button for specific user for next 24 hours when that user click that button. In other words I want to add a funtion in admin panel where a user can't change price for next 24 hours.
$query = "select * from airport_parking where agent_id='$currentid'";
$run = mysqli_query($con,$query);
$datafetch = mysqli_fetch_array($run);
$lastupdated = $datafetch['last_updated'];
<?php
if($lastupdated >= 84600)
{
echo "<a href='edit-service.php?off_id=$currentid'><span class='btn btn-info'>Edit</span></a>";
}else{
echo "<button class='btn btn-info' disabled>Edit</button>";
}
?>
Upvotes: 0
Views: 1091
Reputation: 1451
You should tried like as below
$query = "select * from airport_parking where agent_id='$currentid'";
$run = mysqli_query($con,$query);
$datafetch = mysqli_fetch_array($run);
$lastupdated = $datafetch['last_updated'];
$next24 = strtotime('+1 day', $next24); //add 24 hours in updated date
$current = time(); //get current date
<?php
//check if current then is bigger then next 24 hours
if($current >= $next24)
{
echo "<a href='edit-service.php?off_id=$currentid'><span class='btn btn-info'>Edit</span></a>";
}else{
echo "<button class='btn btn-info' disabled>Edit</button>";
}
?>
Make sure your dates are in unix timestamp,
Upvotes: 0
Reputation: 897
I'm making some assumptions here because your question isn't very complete. Assuming that the $lastupdated is the last time the price was edited (and thus the starting point from which we have to wait 24 hours) then you just need to work out if the $lastupdated was more than 24 hours ago. So you want (I think) to say something like
if((time() - $lastupdated) >= 84600)
{
echo "<a href='edit-service.php?off_id=$currentid'><span class='btn btn-info'>Edit</span></a>";
}else{
echo "<button class='btn btn-info' disabled>Edit</button>";
}
<------- edit ----> If as the previous answer suggest this is specific to the user i.e. if user a updates he has to wait 24 hours, but 2 hours later user b can still update) you will need to check the last time each specific user updated as the other answer suggests
Upvotes: 1