Hello, I am creating an admin page where he can add Job positions to display on the website. Everything is going great, I can do the CRUD. But there is something I don’t know how to do.
I want when the admin posts a job a date will be sent to the database, just to show when that job position was added.
Most, if not all, database engines will do this for you, either with a default value in the field, or by explicitly defining the value when you do your insert.
Most commonly, the latter is done in the form
"INSERT INTO .... (....) VALUES .... `mydatefield` = NOW() ...."
It’s good that the OP has come back and updated the thread now that they have it working - so few people do that. But it seems strange to hand-code something where there is no need.
*ETA - unless the OP doesn’t have the access to change the database config, of course.
I got an idea, create another column in the DB and call it “last updated”.
So when the user sees the job post on the bottom right it will display:
“Last updated” and “job posted:” or keep the last updated for the admin to see. <3
I like to have separate “created” and “last updated” dates where I have a need to sort things by date. Apart from anything else, a “created” date/time may be better than relying on sorting by an id field if you want to see the order things are created.
“Here’s when your posting was created, here’s when you last made a change to it, and here’s when you closed it. Your total time from post-to-close was … (How long has my job search gone on), your total time from last-update-to-close was … (How long did it take me to actually find a candidate i liked), your total time between post-to-update was …” (This, to the customer, is ‘how long did it take me to get my job posting correct’)
unless I’m jumping to conclusions, normally you’d allow the database again to create an automatically-incrementing id for each new row you create, whether it’s a job or anything else. That’s normally referred to as the id and would be unique. By putting it into a form field, I’m presuming you are asking the user to provide it, which opens up all sorts of trouble or, if there’s only one user adding jobs, gives them the task of keeping a record of the next ID to use, which is something the database can do automatically. You can create an id column as auto-incrementing, don’t refer to it in your ‘insert’ query, and it will automatically have the next id when you insert a new row.