Author Topic: output arrays  (Read 1842 times)

0 Members and 1 Guest are viewing this topic.

BM

  • Guest
output arrays
on: Wed, 13. August 2003 - 17:01:09
Small annoyance with arrays here.  Been hacking at it since 9am this morning and only managed to get half way through (not through want of trying & failing  :( ).  Hoping someone can point me in the right direction.

Here's the PHP code I have to get my data into the array structure I think is required;

Code: [Select]

if$arrCategories = $db-get_resultsSELECT id, strCategoryName FROM tbl_categories WHERE intFlag = 1 ORDER BY intOrder ASC;

$intJSCount = 1; //required for something else

$arrDynMenu = array;

foreach$arrCategories as $category

  array_push$arrDynMenu$category-strCategoryName = array;

  if$arrSubCategories = $db-get_resultsSELECT id, strSubCategoryName FROM tbl_subcategories WHERE intFlag = 1 AND intMenuID = .$category-id. ORDER BY intOrder ASC;

   foreach$arrSubCategories as $subcategory

    array_push$arrDynMenu$category-strCategoryName,  array'id'=$subcategory-id,'strSubCategory'=$subcategory-strSubCategoryName;

  

  

  $intJSCount++;







I'm using ez_sql so ignore the SQL statements - they do what I want.
Here's the array output of "$arrDynMenu";

Code: [Select]

Array



    Jackets = Array

        

            0 = Array

                

                    id = 4

                    strSubCategory = PC

                



            1 = Array

                

                    id = 5

                    strSubCategory = Argyle

                



            2 = Array

                

                    id = 6

                    strSubCategory = Baru

                



        



    Kilts = Array

        

            0 = Array

                

                    id = 1

                    strSubCategory = Long

                



            1 = Array

                

                    id = 3

                    strSubCategory = Short

                



            2 = Array

                

                    id = 2

                    strSubCategory = Medium

                



        







What I'm trying to get to is having the vLibTemplate coding within the HTML page displaying it similar to this;

Jackets
 4  PC
 5  Argyle
 6  Baru

Kilts
1  Long
2  Short
3  Medium


I tried to hack about with the loops code in the examples, but since there's an extra array in my effort, I failed  :o


Any help is much appreciated & thanks in advance.

Yaslaw Kowalejeff

  • Guest
output arrays
Reply #1 on: Thu, 14. August 2003 - 09:34:54
1 Array more and then it works...

Code: [Select]
Array



   b0=Array cat= 'Jackets',

                subcat = Array

        

            0 = Array

                

                    id = 4

                    strSubCategory = PC

                


In the Template_


Code: [Select]
tmpl_loop menu

  tmpl_var cat

  tmpl_loop subcat

    tmpl_var id tmpl_var strSubCategory

  /tmpl_loop

/tmpl_loop

releasedj

  • Guest
output arrays
Reply #2 on: Thu, 14. August 2003 - 10:15:10
Try this:

Code: [Select]

if$arrCategories = $db-get_resultsSELECT id, strCategoryName FROM tbl_categories WHERE intFlag = 1 ORDER BY intOrder ASC;

   $intJSCount = 1; //required for something else

   $arrDynMenu = array;

   $i=0;

   foreach$arrCategories as $category

      $arrDynMenu$i = array'category' = $category-strCategoryName, 'subCategory' = array ;

      if$arrSubCategories = $db-get_resultsSELECT id, strSubCategoryName FROM tbl_subcategories WHERE intFlag = 1 AND intMenuID = .$category-id. ORDER BY intOrder ASC;

         foreach$arrSubCategories as $subcategory

            array_push$arrDynMenu$i'subCategory',  array'id'=$subcategory-id,'strSubCategory'=$subcategory-strSubCategoryName;

        

      

      $intJSCount++;

      $i++;

  





Take a closer look at the TMPL_LOOP documentation @ /docs/multihtml/..._tmpl_loop.html
About halfway down you'll notice an example with an inner loop.

Regards,

Kelvin

BM

  • Guest
output arrays
Reply #3 on: Thu, 14. August 2003 - 13:49:06
Thanks guys.

Of course the array is in the correct format,  but for some odd reason (my doing most probably) I just can't get it to output to the html template and it's driving me crazy.  Spent a day and a half on this so far  :x  

This code is wrong,  but can any of you guys who are more proficient with vLib and multiple arrays tell me where it is wrong please.  

Code: [Select]

$ii=0;

$categoriesLoop = array;

foreach$arrDynMenu as $alldetails = $catdetails

$innerLoop = array;

foreach$catdetails as $pish=$catname

   array_push$innerLoop, array'id'=$catdetailssubCategory$ii'id','subcatname'=$catdetailssubCategory$ii'strSubCategory';

   $ii++;



array_push$categoriesLoop, array'catname'=$catname,'innerLoop'=$innerLoop;





I read the docs before and after your post Kelvin, but as much as they make sense,  I suspect I'm lacking an understanding of the structure the array should be in for vLib.  

TIA again.

releasedj

  • Guest
output arrays
Reply #4 on: Thu, 14. August 2003 - 15:23:24
Try this. It uses the loop functions that enable you to build a loop more intuitively.

Code: [Select]

if$arrCategories = $db-get_resultsSELECT id, strCategoryName FROM tbl_categories WHERE intFlag = 1 ORDER BY intOrder ASC;



   $tmpl-newLoop'loop_name';

   foreach$arrCategories as $category

  

      $inner_loop = array;

      if$arrSubCategories = $db-get_resultsSELECT id, strSubCategoryName FROM tbl_subcategories WHERE intFlag = 1 AND intMenuID = .$category-id. ORDER BY intOrder ASC;

      

         foreach$arrSubCategories as $subcategory

        

            array_push$inner_loop,  array'id'=$subcategory-id,'strSubCategory'=$subcategory-strSubCategoryName;

        

      

      $tmpl-addRow array'category' = $category-strCategoryName, 'inner_loop' = $inner_loop, 'loop_name';

  

   $tmpl-addLoop'loop_name';





I hope this helps. If not I'll try to do something a little more detailed.

BM

  • Guest
output arrays
Reply #5 on: Thu, 14. August 2003 - 16:47:23
Thanks v. much Kelvin.  The above code worked a treat and has helped me understand arrays in vLib much better.    

Hope I'm not here for a while  :)

Thanks again

releasedj

  • Guest
output arrays
Reply #6 on: Thu, 14. August 2003 - 17:04:15
No problem. Glad to have been of help.