Announcement

Collapse
No announcement yet.

I'm tired of trying to make this mvt:while loop work, need help!!

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

    I'm tired of trying to make this mvt:while loop work, need help!!

    Hello forum:
    I've been beating my head against the wall too long. Guess I'd better ask the experts.
    I am attempting to use a mvt:while to read an array with 3 elements:
    <mvt:comment> create array </mvt:comment>
    <mvt:assign name="g.ratesfld" value="l.ratesfld" />
    <mvt:assign name="g.arraysize" value="miva_array_elements( g.ratesfld )" />
    <mvt:assign name="g.idx" value="1" />
    <mvt:while expr="g.idx LE g.arraysize">
    &mvt:global:ratesfld[g.idx];<br>
    <mvt:assign name="g.idx" value="g.idx + 1 " />
    </mvt:while>

    If I code the bolded line with the variable g.idx as the index: &mvt:global:ratesfld[g.idx]; it fails with message saying that the index must be a positive integer. This code also fails: &mvt:global:ratesfld[&mvt:global:idx;];<br>
    If I code this line this way, it works: &mvt:global:ratesfld[1];<br>

    What gives?
    Cheers, Larry
    Last edited by wajake41; 07-02-15, 05:42 PM.
    Larry
    Luce Kanun Web Design
    www.facebook.com/wajake41
    www.plus.google.com/116415026668025242914/posts?hl=en



    #2
    Re: I'm tired of trying to make this mvt:while loop work, need help!!

    Instead of miva_array_elements(g.ratesfld) I think you need miva_array_max(g.ratesfld).
    Gordon Currie
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit Any Document Easily | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Re: I'm tired of trying to make this mvt:while loop work, need help!!

      Hi Gordon:
      miva_array_elements is returning a 3 so I think that's OK. I have 3 entries in the array.

      The problem is: &mvt:global:ratesfld[&mvt:global:idx;]; is throwing "Array index must be positive integer"
      while &mvt:global:ratesfld[1]; doesn't fail and the first array entry is displayed.
      Larry
      Larry
      Luce Kanun Web Design
      www.facebook.com/wajake41
      www.plus.google.com/116415026668025242914/posts?hl=en


      Comment


        #4
        Re: I'm tired of trying to make this mvt:while loop work, need help!!

        Theoretically, this should be the code to get array value inside while loop : &mvt:global:ratesfld[&mvt:global:idx;];, but it looks like that when Miva engine finds first mvt tag to output, it concentrates on getting it's value first and in your case, you are creating nesting mvt tags. It is failing to output because it is trying to interpret &mvt:global:ratesfld; first , when it should interpret &mvt:global:idx; first.

        You can always use foreach loops for dealing with arrays, they are safer, as you don't need to know the size of array in advance, and you simply can't go beyond the size of array. They also provide POS1 counter if you need to keep record of iterations as well.
        Rajnish Sinha
        ---------------------
        https://twitter.com/rajnishsi

        Comment


          #5
          Re: I'm tired of trying to make this mvt:while loop work, need help!!

          IIRC, you can't use one mvt: entity inside another. Instead of

          &mvt:global:ratesfld[&mvt:global:idx;];

          -- I'd try:

          &mvt:global:ratesfld[g.idx];

          If that doesn't work, you'll need to use mvt:foreach instead of mvt:while, as rajnihsi wrote.
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Re: I'm tired of trying to make this mvt:while loop work, need help!!

            Hi rajnishsi:
            IMO, If that behavior is intended, it seems to limit the practical use of the mvt:while command.

            So I'm trying to read my array with a mvt:foreach loop and can't make that work either.
            This is my array: <mvt:assign name="g.ratesfld" value="l.ratesfld" />
            This is the foreach loop I've been trying to make work:
            <mvt:foreach array="ratesfld" iterator="idx">
            aa &mvt:idx:ratesfld;<br>
            </mvt:foreach>

            Something ain't right and Larry's getting frustrated!

            BTW Are you a real Rajneeshee. Did I ever see you at PDX?:)

            Larry
            Last edited by wajake41; 07-03-15, 09:13 AM.
            Larry
            Luce Kanun Web Design
            www.facebook.com/wajake41
            www.plus.google.com/116415026668025242914/posts?hl=en


            Comment


              #7
              Re: I'm tired of trying to make this mvt:while loop work, need help!!

              Actually, I think I remember having problems using mvt:foreach with global variables. Their scope is limited to the l.settings structure, so they can't reference globals. Sorry for the bad advice ... Going back to the mvt:while loop, if my earlier suggestion didn't work, you could try using:

              <mvt:eval expr="g.ratesfld[g.idx]" />

              -- to output the desired value; that works with global variables.

              Also, I'm curious about that initialization:

              <mvt:assign name="g.ratesfld" value="l.ratesfld" />

              Template scripts don't have much access to local variables. Are you sure that l.ratesfld contains the right data?
              Kent Multer
              Magic Metal Productions
              http://TheMagicM.com
              * Web developer/designer
              * E-commerce and Miva
              * Author, The Official Miva Web Scripting Book -- available on-line:
              http://www.amazon.com/exec/obidos/IS...icmetalproducA

              Comment


                #8
                Re: I'm tired of trying to make this mvt:while loop work, need help!!

                Hi Kent:
                RE: <mvt:assign name="g.ratesfld" value="l.ratesfld" />
                From my Latu variable dump:
                465 g.ratesfld[1] &mvt:global:ratesfld[1]; 0
                466 g.ratesfld[2] &mvt:global:ratesfld[2]; 0.084
                467 g.ratesfld[3] &mvt:global:ratesfld[3]; 0605

                so I think the array is OK.
                I can read the array in a while loop even thought the entries are global.
                For example: &mvt:global:ratesfld[1];

                Now I just want to read the array in a foreach loop as you suggested.
                I proven many times that this foreach loop doesn't work:
                <mvt:foreach array="ratesfld" iterator="idx">
                aa &mvt:idx:ratesfld;<br>
                </mvt:foreach>
                The aa in the loop is never displayed so it appears that the foreach loop is being ignored because it's coded incorrectly.
                Guessing the problem is in the array="ratesfld" value.

                I would like to know how to read my self generated arrays (not Miva's) but sure am having trouble doing it.
                Cheers, Larry
                Larry
                Luce Kanun Web Design
                www.facebook.com/wajake41
                www.plus.google.com/116415026668025242914/posts?hl=en


                Comment


                  #9
                  Re: I'm tired of trying to make this mvt:while loop work, need help!!

                  I guess you missed my earlier thought about not using mvt:foreach with global variables? The loop is coded correctly, but array="ratesfld" tells the engine to look in l.settings:ratefld, or maybe l.all_settings:ratesfld -- sorry, I'm not sure which would be correct in this case. But it definitely won't look in g.ratesfld, which is where your data is.
                  Kent Multer
                  Magic Metal Productions
                  http://TheMagicM.com
                  * Web developer/designer
                  * E-commerce and Miva
                  * Author, The Official Miva Web Scripting Book -- available on-line:
                  http://www.amazon.com/exec/obidos/IS...icmetalproducA

                  Comment


                    #10
                    Re: I'm tired of trying to make this mvt:while loop work, need help!!

                    Hi Kent:
                    Thanks for your reply.
                    I tried making the array a local and can't find the local variables in my Latu dump.
                    I then attempted to create 3 arrays using different qualification on the array name:
                    <mvt:assign name="ratesfldarray" value="l.ratesfld" />
                    <mvt:assign name="g.ratesfldarray1" value="l.ratesfld" />
                    <mvt:assign name="l.ratesfldarray2" value="l.ratesfld" />

                    This is what that shows in the Latu dump for these 3 arrays:
                    465 g.ratesfldarray[1] &mvt:global:ratesfldarray[1]; 0
                    466 g.ratesfldarray[2] &mvt:global:ratesfldarray[2]; 0.084
                    467 g.ratesfldarray[3] &mvt:global:ratesfldarray[3]; 0605
                    468 g.ratesfldarray1[1] &mvt:global:ratesfldarray1[1]; 0
                    469 g.ratesfldarray1[2] &mvt:global:ratesfldarray1[2]; 0.084
                    470 g.ratesfldarray1[3] &mvt:global:ratesfldarray1[3]; 0605

                    The array defined as: <mvt:assign name="ratesfldarray" value="l.ratesfld" /> defaults to global.
                    The array defined as: <mvt:assign name="g.ratesfldarray1" value="l.ratesfld" /> is global as expected.
                    The array defined as: <mvt:assign name="l.ratesfldarray2" value="l.ratesfld" /> does not appear in my Latu dump.

                    There appears to be no local array variables created for the array defined as local with this statement:
                    <mvt:assign name="l.ratesfldarray2" value="l.ratesfld" />

                    I ran the Latu dump immediately after creating the 3 arrays.

                    I still cannot get my foreach loop to execute. It's being ignored by the Miva render.
                    Still don't know what to code as the array name in the foreach loop even with these three differently named arrays. Have tried to do it numerous ways.

                    Still puzzled!
                    Cheers, Larry
                    Last edited by wajake41; 07-04-15, 06:11 AM.
                    Larry
                    Luce Kanun Web Design
                    www.facebook.com/wajake41
                    www.plus.google.com/116415026668025242914/posts?hl=en


                    Comment


                      #11
                      Re: I'm tired of trying to make this mvt:while loop work, need help!!

                      I believe Kent is correct. In Foreach you still can only access a local array/structure. You need to assign the array to the l.settings and create a branch.

                      <mvt:assign name="l.settings:MyNewBranch" value="g.MyGlobVar" />

                      Then in the foreach:

                      <mvt:foreach iterator="mybranch" array="MyNewBranch">

                      edit: it's possible you need to precise like this:

                      <mvt:foreach iterator="mybranch" array="l.settings:MyNewBranch">


                      you will then have access to:

                      mybranch:mem1
                      mybranch:mem2 etc.

                      which is equiv to:

                      l.settings:MyNewBranch[1]:mem1
                      l.settings:MyNewBranch[1]:mem2

                      second time through the loop:

                      mybranch:mem1
                      mybranch:mem2 etc.

                      which is equiv to:

                      l.settings:MyNewBranch[2]:mem1
                      l.settings:MyNewBranch[2]:mem2

                      Note: if for some reason l.settings doesnt work, use l.all_settings

                      Also added: there are many example in the default page templates to follow, like the CTGY product display layout. However, the key is assigning the global to the local and creating a branch from it.

                      Scott
                      Last edited by ids; 07-04-15, 10:33 AM.
                      Need to offer Shipping Insurance?
                      Interactive Design Solutions https://www.myids.net
                      MivaMerchant Business Partner | Certified MivaMerchant Web Developer
                      Competitive Rates, Custom Modules and Integrations, Store Integration
                      AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
                      My T-shirt Collection is mostly MivaCon T-shirts!!

                      Comment


                        #12
                        Re: I'm tired of trying to make this mvt:while loop work, need help!!

                        Thanks for the replies:
                        results so far:
                        I've created a local array from my global array
                        <mvt:assign name="l.settings:Myarray" value="g.ratesfldarray" />
                        I've verified it's size and content:
                        <mvt:assign name="g.Myarraysize" value="miva_array_elements( l.settings:Myarray)" />
                        array size = &mmvt:global:Myarraysize;
                        array entry 2 = &mvt:myarray[2];

                        array size displays as 3
                        array entry[2] displays as 0.084

                        However this foreach loop is totally ignored by the Miva render:
                        <mvt:foreach iterator="Myarray" array="l.all_settings:Myarray">
                        <mvt:comment> aa &mvt:Myarray:salesfld; <br> </mvt:comment>
                        aa<br>
                        </mvt:foreach>

                        I would expect to see 3 lines of aa if the foreach look was being executed.
                        I've also tried using the array name: l.settings:Myarray without success.

                        Miva doesn't like the way I've coded my foreach statement.
                        Any ideas?

                        Thanks, Larry
                        Last edited by wajake41; 07-04-15, 07:04 PM.
                        Larry
                        Luce Kanun Web Design
                        www.facebook.com/wajake41
                        www.plus.google.com/116415026668025242914/posts?hl=en


                        Comment


                          #13
                          Re: I'm tired of trying to make this mvt:while loop work, need help!!

                          I believe the foreach assumes l.settings: so just use MyArray (and don't use MyArray as the interator).
                          Bruce Golub
                          Phosphor Media - "Your Success is our Business"

                          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                          phosphormedia.com

                          Comment


                            #14
                            Re: I'm tired of trying to make this mvt:while loop work, need help!!

                            Thanks to everyone I have this working.
                            This is the template code I'm using to display the contents of my 3 member array;
                            <mvt:assign name="l.settings:Myarray" value="g.ratesfldarray" />
                            <mvt:assign name="g.Myarraysize" value="miva_array_elements( l.settings:Myarray)" />
                            MYarray size = &mvt:global:Myarraysize; <br>
                            array entry 1 = &mvt:myarray[1]; <br>
                            array entry 2 = &mvt:myarray[2]; <br>
                            array entry 3 = &mvt:myarray[3]; <br>

                            <mvt:foreach iterator="arrayValue" array="Myarray" >
                            &mvt:arrayValue; <br>
                            </mvt:foreach>

                            This is the result when it executes:
                            MYarray size = 3
                            array entry 1 = 0
                            array entry 2 = 0.084
                            array entry 3 = 0605
                            0
                            0.084
                            0605

                            Thanks again for your help!
                            Larry
                            Larry
                            Luce Kanun Web Design
                            www.facebook.com/wajake41
                            www.plus.google.com/116415026668025242914/posts?hl=en


                            Comment


                              #15
                              Re: I'm tired of trying to make this mvt:while loop work, need help!!

                              Hi Larry..we haven't met yet. But would love to do so sometime in future.
                              Rajnish Sinha
                              ---------------------
                              https://twitter.com/rajnishsi

                              Comment

                              Working...
                              X