I am making a browser game, and I want someone to want to build a building, in minutes, and then it ends.
Given that this is your actual goal, I recommend just keeping the original building with a time stamp.
I know that you tagged your question using PHP, but I donโt want to include all the overhead of processing mysql queries in PHP, especially since I donโt know how you prefer to execute queries or what structure you use suing, so here is some pseudo-code for solving this "building" problem:
build.php
building_type_id = sanitize(POST['id']) user_id = current_user['id'] query('INSERT INTO buildings (user_id, building_type_id, created_at) VALUES (' + user_id + ', ' + building_type_id + ', CURRENT_TIME)');
my_buildings.php
user_id = current_user['id'] completed_buildings = query('SELECT * FROM buildings b LEFT OUTER JOIN building_types t ON b.building_type_id = t.id WHERE DATE_ADD(b.created_at, INTERVAL t.construction_time SECOND) < NOW();') under_construction = query('SELECT * FROM buildings b LEFT OUTER JOIN building_types t ON b.building_type_id = t.id WHERE DATE_ADD(b.created_at, INTERVAL t.construction_time SECOND) > NOW();')
Hope this helps!
Steven xu
source share