1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How do i get MySQL dbs to talk to each other?

Discussion in 'MySQL' started by onlyican.com, Dec 22, 2005.

  1. #1
    OK, total newby in mysql, learning slowly but surley

    I have 2 db's

    one holds stock info
    one holds client info

    I want to make it so when a client buys a product, the supply number on the stock db will go down by how ever many they buy

    and when we restock, to enter information to make the stock go up.

    So how do i do this.

    any good sites to learn will be excellent.

    I need to learn this first, rather than 300 pages deep into a book.

    I am using MySQL version 3.23.51nt and also using mysql-front
     
    onlyican.com, Dec 22, 2005 IP
  2. l234244

    l234244 Peon

    Messages:
    1,225
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Im a bit of a newbie aswell to php/mysql so this is just my recommendation.

    Firstly, I dont think you need two databases just the one would be sufficient. In the database you may have three tables; one may have columns for customerid, name, address, etc the second table might have productsid and quantity , and a third might have orders productsid and customerid. When someone orders a product you would just use the following in your script after the product is ordered:

    UPDATE database_name quantity = quantity - 1
    WHERE productid = 5

    The "-1" would have to be a variable returning a number so that if someone orders 2 or 3 then the database is updated respectively.

    The "5" would be set to a unique number you give to the product in your database.

    To increase the number you use the same sql statment but change the "-" to "+".

    Im pretty sure some php/mysql expert will come along soon to give a better explanation
     
    l234244, Dec 22, 2005 IP
    MattEvers likes this.
  3. ServerUnion

    ServerUnion Peon

    Messages:
    3,611
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    0
    #3
    might be a good idea to have this info all in one database to limit the number of database connections each time you need an update.

    the SQL sytax previosly posted looks like it will work.
     
    ServerUnion, Dec 22, 2005 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    My Mistake

    I do have 1 db, i have 2 tables inside the db

    1st table with product info (a unique product id is on off them)
    2nd table client info, what they brought, date, ect, for invoices and checking sales

    What i wanted was everytime a product is sold, table 2 takes one off the field in table 1.

    What i have done now is another query
    select the field, add 1 to number, update field.
     
    onlyican.com, Dec 22, 2005 IP
  5. ServerUnion

    ServerUnion Peon

    Messages:
    3,611
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    0
    #5
    OK, well the code given by the other user:

    UPDATE database_name quantity = quantity - 1
    WHERE productid = 5

    Would do that all in one step
     
    ServerUnion, Dec 22, 2005 IP
  6. dsm56

    dsm56 Active Member

    Messages:
    863
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    78
    #6
    dont forget the SET before quantity
     
    dsm56, Dec 22, 2005 IP
  7. l234244

    l234244 Peon

    Messages:
    1,225
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Good shout dsm56,

    UPDATE database_name SET quantity = quantity - 1
    WHERE productid = 5
     
    l234244, Dec 22, 2005 IP
  8. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ok then

    I have 4 columns in the table
    su_price, IVA, RE and total_price

    Is there a way to get total_price to be
    (su_price * IVA / 100)* RE / 100
     
    onlyican.com, Dec 22, 2005 IP
  9. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #9
    simply follow what l234244 stated, and use

    update database_name set quantity= quantity-1 , total_price = your formula

    where product...
     
    legend2, Jan 6, 2006 IP