how to manipulate ids and names from database?

0 Marcio Bremer · July 23, 2015
Hi, watching the tutorials from thenewboston, I try to make a spun program to my market. and I have created 3 tables.

in table order I have person_id which is foreign key from person (id) and product_id which is foreign key from product (id).

my problem is, I dont find how to pickup this ids and put in order table, on my program I did a combobox who pickup names from
database, but I dont know how to pick the ids and insert on database on order table. someone can give me an idea?

ps. Tomorrow I'll post the codes. thanks!

Post a Reply


Oldest  Newest  Rating
0 Lars Christensen · July 24, 2015
If you are simply using a plain HTML combo-box with <select> elements, you can specify an id attribute on each select element and use the id from the database. I assume you are already using a product name from the product database? 
Both can be injected when generating the combo-box.

For person ID, you can do the same unless the person would have to be logged in to use your market. That way you could grab the id of the logged in person.

Then you can do a INSERT/UPDATE into the order table with these 2 ids.

  <option value="volvo" id="001">Volvo</option>
  <option value="saab" id="002">Saab</option>
  <option value="mercedes" id="003">Mercedes</option>
  <option value="audi" id="004">Audi</option>

INSERT into order (person_id, product_id)
VALUES ('<logged in person_id>', '001')

The logged in person has now made an order for a Volvo.

Hope it helped. :)
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator