Announcement

Collapse
No announcement yet.

Infinite While Loop MvOPENVIEW

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Infinite While Loop MvOPENVIEW

    This is the first time that I have used MvOPENVIEW in a module so I am not sure what I am doing wrong. I am trying to look up to see if a product is using a variant price and then output the parts that make up that variant price. The MvWHILE only displays the first value in the database in an infinite loop. It should display three values and then exit but it isn't for some reason.

    Code:
    <MvOPENVIEW NAME="Merchant" VIEW="PVP" QUERY="{ 'SELECT * FROM s01_ProductVariantPricing WHERE product_id = ' $ l.product:id }">    <MvOPENVIEW NAME="Merchant" VIEW="PV" QUERY="{ 'SELECT * FROM s01_ProductVariantParts WHERE product_id = ' $ PVP.d.product_id }">
            <MvWHILE EXPR = "{ (NOT PV.d.EOF) AND (PV.d.product_id EQ PVP.d.product_id) }">
                <MvEVAL EXPR="{ 'Part ID: ' $ PV.d.part_id $ ' <br>' }">
            </MvWHILE>
        <MvCLOSEVIEW NAME="Merchant" VIEW="PV">
    <MvCLOSEVIEW NAME="Merchant" VIEW="PVP">
    Last edited by K Series Parts; 08-05-14, 07:38 AM.
    Chris Dye
    http://www.kseriesparts.com

    #2
    Re: Infinite While Loop MvOPENVIEW

    Dear Chris,

    (NOT PV.d.EOF) AND (PV.d.product_id EQ PVP.d.product_id) }">

    I believe if you never find matching ID's it will run forever because of the AND.

    If you want it to run until the EOF OR your find matching ID's then you should use: OR
    Last edited by Nerd Boy Inc; 08-05-14, 07:42 AM.
    Thank You,

    Nerd Boy

    http://www.nerdboyinc.com

    1-855-Nerd-Boy

    Comment


      #3
      Re: Infinite While Loop MvOPENVIEW

      The ProductVariantParts table only has three values and the product_id matches for all three. I tested it without the d.EOF and changing it to OR and it produced the same infinite loop.
      Last edited by K Series Parts; 08-05-14, 08:00 AM.
      Chris Dye
      http://www.kseriesparts.com

      Comment


        #4
        Re: Infinite While Loop MvOPENVIEW

        Dear Chris,

        Start by breaking it down in parts without the AND / OR to see if you can break out that way, then start adding parts back in.
        Thank You,

        Nerd Boy

        http://www.nerdboyinc.com

        1-855-Nerd-Boy

        Comment


          #5
          Re: Infinite While Loop MvOPENVIEW

          I am not sure what you mean, not really sure how I can break it down any more. if I remove the AND/OR call and just have the .eof it produces the infinite loop. to me, it seems that adding the product_id EQ product_id would prevent that loop but it doesn't.
          Chris Dye
          http://www.kseriesparts.com

          Comment


            #6
            Re: Infinite While Loop MvOPENVIEW

            Dear Chris,

            I feel stupid.....

            You need to add:

            <MvSKIP NAME = "Merchant" VIEW = "INSERTYOUSTUFFHERE" ROWS = 1>

            Before your MVWHILE statement, this allows you to cycle through the DB.
            Last edited by Nerd Boy Inc; 08-05-14, 08:05 AM.
            Thank You,

            Nerd Boy

            http://www.nerdboyinc.com

            1-855-Nerd-Boy

            Comment


              #7
              Re: Infinite While Loop MvOPENVIEW

              that was it, thank you! it has to go at the end of the while loop but saying that helped based upon looking at mvscript as well! I am curious why that call is needed and why it doesn't just loop based upon values you tell it.

              Code:
              <MvOPENVIEW NAME="Merchant" VIEW="PVP" QUERY="{ 'SELECT * FROM s01_ProductVariantPricing WHERE product_id = ' $ l.product:id }">	<MvOPENVIEW NAME="Merchant" VIEW="PV" QUERY="{ 'SELECT * FROM s01_ProductVariantParts WHERE product_id = ' $ PVP.d.product_id }">
              		<MvWHILE EXPR = "{ (NOT PV.d.EOF) AND (PV.d.product_id EQ PVP.d.product_id) }">
              			<MvEVAL EXPR="{ 'Part ID: ' $ PV.d.part_id $ ' <br>' }">
              			<MvSKIP NAME="Merchant" VIEW="PV" ROWS=1>
              		</MvWHILE>
              	<MvCLOSEVIEW NAME="Merchant" VIEW="PV">
              <MvCLOSEVIEW NAME="Merchant" VIEW="PVP">
              Chris Dye
              http://www.kseriesparts.com

              Comment


                #8
                Re: Infinite While Loop MvOPENVIEW

                Dear Chris,

                My guess is it allows you to cycle through as needed. You could leave it there update based on something then cycle. It also allows you to cycle my X number of Rows as well.
                Thank You,

                Nerd Boy

                http://www.nerdboyinc.com

                1-855-Nerd-Boy

                Comment


                  #9
                  Re: Infinite While Loop MvOPENVIEW

                  One other quick question, is there a way to add values in the while loop?
                  Chris Dye
                  http://www.kseriesparts.com

                  Comment


                    #10
                    Re: Infinite While Loop MvOPENVIEW

                    Dear Chris,

                    Not sure what you mean.
                    Thank You,

                    Nerd Boy

                    http://www.nerdboyinc.com

                    1-855-Nerd-Boy

                    Comment


                      #11
                      Re: Infinite While Loop MvOPENVIEW

                      The final step to what I am doing is pulling the cost and price from the products table. I want to add together l.cost_total and l.price_total for each variant to get a total cost and a total price for the product.

                      Code:
                      <MvOPENVIEW NAME="Merchant" VIEW="PROD" QUERY="{ 'SELECT id, code, price, cost FROM s01_Products WHERE id = ' $ PV.d.part_id }">	<MvWHILE EXPR = "{ (NOT PROD.d.EOF) AND (PROD.d.id EQ PV.d.part_id) }">
                      		<MvASSIGN NAME="l.cost_total" VALUE="{ PROD.d.cost * PV.d.quantity }">
                      		<MvASSIGN NAME="l.price_total" VALUE="{ PROD.d.price * PV.d.quantity }">
                      		<MvSKIP NAME="Merchant" VIEW="PROD" ROWS=1>
                      	</MvWHILE>
                      <MvCLOSEVIEW NAME="Merchant" VIEW="PROD">
                      Chris Dye
                      http://www.kseriesparts.com

                      Comment


                        #12
                        Re: Infinite While Loop MvOPENVIEW

                        Dear Chris,

                        That should work, but depending on how you exit out of the Function the Local Variable may not be available. You may need to use a Global Variable. If you are not sure what I mean, the Docs explain this very well.
                        Thank You,

                        Nerd Boy

                        http://www.nerdboyinc.com

                        1-855-Nerd-Boy

                        Comment


                          #13
                          Re: Infinite While Loop MvOPENVIEW

                          If you do the following it will only give you double the last values in the while loop, which makes sense since l.cost_total and l.price_total are overwriting on each loop. It does the same if you pull them out of the while loop.

                          Code:
                          <MvASSIGN NAME="g.combo_cost" VALUE="{ l.cost_total + l.cost_total }"><MvASSIGN NAME="g.combo_price" VALUE="{ l.price_total + l.price_total }">
                          Chris Dye
                          http://www.kseriesparts.com

                          Comment


                            #14
                            Re: Infinite While Loop MvOPENVIEW

                            Dear Chris,

                            Try this:

                            <MvOPENVIEW NAME="Merchant" VIEW="PROD" QUERY="{ 'SELECT id, code, price, cost FROM s01_Products WHERE id = ' $ PV.d.part_id }"> <MvWHILE EXPR = "{ (NOT PROD.d.EOF) AND (PROD.d.id EQ PV.d.part_id) }">
                            <MvASSIGN NAME="l.cost_total" VALUE="{ PROD.d.cost * PV.d.quantity }">
                            <MvASSIGN NAME="l.price_total" VALUE="{ PROD.d.price * PV.d.quantity }">
                            <MvASSIGN NAME="g.combo_cost" VALUE="{ g.combo_cost + l.cost_total }">
                            <MvASSIGN NAME="g.combo_price" VALUE="{ g.combo_price + l.price_total }">
                            <MvSKIP NAME="Merchant" VIEW="PROD" ROWS=1>
                            </MvWHILE>
                            <MvCLOSEVIEW NAME="Merchant" VIEW="PROD">

                            You will need to Zero out you Global Variables before you start looping.
                            Thank You,

                            Nerd Boy

                            http://www.nerdboyinc.com

                            1-855-Nerd-Boy

                            Comment


                              #15
                              Re: Infinite While Loop MvOPENVIEW

                              Dear Chris,

                              This should work too (not tested) with same remark about zeroing out first.

                              <MvOPENVIEW NAME="Merchant" VIEW="PROD" QUERY="{ 'SELECT id, code, price, cost FROM s01_Products WHERE id = ' $ PV.d.part_id }"> <MvWHILE EXPR = "{ (NOT PROD.d.EOF) AND (PROD.d.id EQ PV.d.part_id) }">
                              <MvASSIGN NAME="g.combo_cost" VALUE="{ g.combo_cost + (PROD.d.cost * PV.d.quantity) }">
                              <MvASSIGN NAME="g.combo_price" VALUE="{ g.combo_price + (PROD.d.price * PV.d.quantity) }">
                              <MvSKIP NAME="Merchant" VIEW="PROD" ROWS=1>
                              </MvWHILE>
                              <MvCLOSEVIEW NAME="Merchant" VIEW="PROD">
                              Thank You,

                              Nerd Boy

                              http://www.nerdboyinc.com

                              1-855-Nerd-Boy

                              Comment

                              Working...
                              X