Jonas Ley Jonas Ley - 4 months ago 15
MySQL Question

Create unique ID for users offer

I have a SQL-table for user information and a table for offers. If a user uploads an offer, it gets a unique id, aswell as a "belonging_id" with the users id in it.

Now I want to change an element after the offer is already in my Database. But the only information I have is the user's id. And it is possible for a user to have multiple offers.

So my Question is: How can I call one specific offer with a unique id to Update it?


Please give us your SQL Table schemes.

To help you, I think your request should be something like :

SELECT * FROM offers WHERE belonging_id = id_user


You need to have a unique identifier (something like primary key, or a UNIQUE field) in your table offers if you want to retrieve a specific offer among all the user's offers.

When you insert data in a table, you can retrieve the last inserted id. For exemple, in PHP (using PDO extension) you can do : echo $db->lastInsertId();


Let's suppose the user ends on a page send_offer.php after he sent the offer in the database. You should then generate a unique link like : http://edit_offer.php/?id_offer=the_id_of_the_offer_just_sent

This unique link should be stored in your table offers, so when the user wants to edit one of his offer, he only has to access your site with this link.

This link should point to a web page where there's a form, in which you'll want to load the data of the offer corresponding to the above link.