Closed Thread
Results 1 to 5 of 5

Thread: Help Needed.

  1. #1
    snoopy85 is offline Newbie
    Join Date
    May 2007
    Posts
    2
    Rep Power
    0

    Help Needed.

    Hi all,

    My database consists of tables named "purchases_0108" to "purchases_0708". For the 4 digits of the tables' name, the first 2 digits stands for the month and the last 2 digits stands for the year.

    The tables consist of fields :

    1) "name" (Company name that I bought the item from)
    2) "date" (Date I bought the item)
    3) "rate" (Currency rate when I bought the item)
    4) "invoice" (Invoice number of the item)
    5) "article" (Article number of the item)
    6) "description" (Description of the item)
    7) "size" (Size of the item)
    8) "material" (Material of the item)
    9) "finishing" (Finishing of the item)
    10) "quantity" (Quantity of the item)
    11) "price" (Price of the item)

    I also have the same set of tables named "sales_0108" to "sales_0708". Both "purchases" and "sales" tables have the same fields.

    What I wish to achieve is have a code which can output my stock balance. There is similar items purchased at different dates in "purchases" tables and also same items sold at different dates in "sales" table. Which means that I have to add up the quantity for each item in each month of the "purchases" table, and take that to minus the quantity for the same item, if I have sold them, in the "sales" table.

    I only know basic php programming like mysql_query and mysql_fetch_array, using the while ($row = mysql_fetch_array($result)) to output the records.

    Any help from you guys is greatly appreciated. Thanks in advance.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Help Needed.

    Do you have any code you can post? Where exactly are you stuck at?

    I'm also wondering why you name the tables that way? Why not add two more fields to the table - one for month, one for year. With the two fields added you will be able to filter your results the same as if each year/month had a different table.

  4. #3
    snoopy85 is offline Newbie
    Join Date
    May 2007
    Posts
    2
    Rep Power
    0

    Re: Help Needed.

    Hi Jordan,

    Yup I got people asking me the same questions. Why would I create different months of each table and not just have 1 table for the purchases and 1 table for the sales. It would be much easier to output the balance.

    What I was thinking at first was I wouldn't want too many records in a single table and having different months' table for each purchases and sales table would make it much neaty.

    And at the end of each year I would create a table for the year end balance of each item.

    I apologize if my structure of database is not good at all. Kindly give your guidance and advice. Thank you!

  5. #4
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Help Needed.

    to get a stock balance should be a script first adding up all purchases (# items times price) for each row, then subtracting all sales in the same way.

    but ofcourse, then you couldn't have any waste products and so on. then you need to sell them for $0...

    that's the main idea atleast.

  6. #5
    Jordan Guest

    Re: Help Needed.

    I believe you should restructure your database table names. You shouldn't worry about how many columns are in a table because you will hardly ever look at the raw tables (you'll use some sort of script, like the one you are trying to build, to view the table). With a rename of your table you can find the stock price with one simple SQL query and sort the results just as easy.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help needed
    By Meskis in forum Request Services
    Replies: 2
    Last Post: 07-15-2011, 09:08 AM
  2. Hello {Help needed}
    By Darkerm in forum Introductions
    Replies: 1
    Last Post: 06-27-2011, 03:59 AM
  3. help needed
    By 24kmax10 in forum C# Programming
    Replies: 2
    Last Post: 03-30-2010, 08:13 AM
  4. Help needed
    By ahmed in forum Linux Installation & Configuration
    Replies: 6
    Last Post: 02-27-2010, 07:56 AM
  5. help needed please
    By greaterfrankie in forum C and C++
    Replies: 10
    Last Post: 11-18-2008, 07:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts