开发者

Making a new sql table, where one of the fields copy data from another table field

I have one existing table for guests, with information such as name, passport number and such.

I want to make a new table for sales, and want to make it so that when a client is chosen from the existing table, certain fields are populated in the new table, such as passport number.

I am doing this with php and ajax.

Could someone point me in the general di开发者_如何学Gorection for where I should be looking to do this?


You can do it from straight sql

$sql = "INSERT INTO sales (guest_id, passport_number) 
        VALUES ($guest_id, (SELECT passport_number FROM guests WHERE guest_id = $guest_id))";


Does the new sales table have to have it's own copy of the passport number, etc?
You can have a relation between the two tables, pointing to data in the original table from the sales table, for new customers that are already in the original table.

Check out:
http://php.about.com/od/learnmysql/ss/mysql_3.htm

http://en.wikipedia.org/wiki/Relational_database

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜