Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question relational databases loop?

    Hey im having a little trouble...
    I am looping through a few tables to calculate interest rates heres the basics for the loop.

    First is a foreach for the loan types and then nested inside that there is a while loop to come up with all the different banks information containing that loan type.

    The kicker is now i need to make adjustments based on loan amount... so i have a table with

    id
    rate_sheet_id
    high_loan_amount
    low_loan_amount
    adjustment

    and what I need to do is test against the high and low loan amount and make an adjustment accordingly... A single sheet may have up to 3 or four of these which is why it is an a seperate table...

    Do i run yet another while loop? or is there a single sql query i can run?
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post
    Just to clarify.... If the loan amount is between the high and the low... then make adjustment... for example you may have these options avaliable for that program.

    So if your loan amount is 300,000 it should subtract .25. I need to know how to find the proper one in this situation

    30,000 - 75000 +.75
    75,001 - 200,000 0
    200,001 - 650,000 -.25
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    since you are working with data in a database you should not be using any FOR loops whatsoever. you would only use those in code (php, coldfusion etc.) when you are displaying the output of your mysql query.

    could you actually show your tables with some sample data and what you are trying to do?

    as for the second question you posted, look up the use of CASE in the mysql manual

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    64
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by guelphdad View Post
    since you are working with data in a database you should not be using any FOR loops whatsoever. you would only use those in code (php, coldfusion etc.) when you are displaying the output of your mysql query.

    could you actually show your tables with some sample data and what you are trying to do?

    as for the second question you posted, look up the use of CASE in the mysql manual

    Sorry maybe i wrote that incorrectly... Buy yes the foreach is for displaying the data i apologize...
    No trees were harmed in the transmission of this message.
    However, a rather large number of electrons were temporarily
    inconvenienced.


  •  

    Posting Permissions

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