Reputation: 315
After trying my self I'm kinda failing, I basically need to build an PHP + SQL system where all i pass is an ID into it and see if that id's license has expired.
if it hasn't expired then rewrite its license down by 1. (license should starts at 20)
So basically: (After connected from an android device passing a String ID)
20
and return true
Upvotes: 1
Views: 243
Reputation: 30170
pseudo code
query = select license from table where id=:id
if count(query) {
if (license <= 0) {
return false
}
license--;
update table set license=:license where id=:id
return true
}
else {
insert into table(id, license) values(:id, 20)
return true
}
Upvotes: 0
Reputation: 1410
I haven't used the standard mysql function calls in a long time, so bear with me.
//Connect stuff has been done...
$query = "SELECT ID, license
FROM table
WHERE ID = '$someID'";
$result = query($query);
if($result->rowCount() > 0){
$row = $result->fetch();
if($row['license'] == 0)
return false;
else{
$license = $row['license'] - 1;
$query = "UPDATE table SET license = '$license' WHERE ID = '$someID'";
query($query);
return true;
}
}
else{
$query = "INSERT INTO table(ID, license) VALUES('$someID', 20)";
query($query);
return true;
}
Upvotes: 1