Wednesday, 15 February 2012

php - Trying to insert one column from table1 into existing column in table2? -



php - Trying to insert one column from table1 into existing column in table2? -

thanks viewing question.

i have 2 tables : clients table.

+--------+---------+--------+------------+--------------+------------+ | id | name | debt | phone | address | products | +--------+---------+--------+------------+--------------+------------+ | 1 | person1 | 55.54 | 8187654545 | planet earth | (none yet) | | 1 | person2 | 55.64 | 8184256595 | planet mars | (none yet) | +--------+---------+--------+------------+--------------+------------+

this products table:

+-----+----------+----------+----------+----------------+-------+ | id | category | name | type | size_in_ounces | cost | +-----+----------+----------+----------+----------------+-------+ | 1 | liquids | product1 | original | 2.7 | 1.99 | | 1 | liquids | product2 | original | 7.7 | 5.99 | | 1 | liquids | product3 | original | 10 | 7.99 | +-----+----------+----------+----------+----------------+-------+

i trying add together name column row in products table products column in clients table. trying accomplish is, on query, show in clients table, , if possible clients debt column increment in cost accordingly.

+--------+---------+--------+------------+--------------+------------+ | id | name | debt | phone | address | products | +--------+---------+--------+------------+--------------+------------+ | 1 | person1 | 63.49 | 8187654545 | planet earth | product3 | | 1 | person2 | 57.63 | 8184256595 | planet mars | product1 | +--------+---------+--------+------------+--------------+------------+

i tried this: sql gives me error. know next code wrong can give thought of i'm trying accomplish.

insert `clients` (products) `name` = "person1" select `name` `products` `name` = "product3";

and here silly thing; if code :

insert `clients` (products) select `name` `products` `name` = "product3";

it creates new client every column null or empty except products column adds product3. weird right?

php mysql table

No comments:

Post a Comment