vLIB
Welcome, Guest. Please login or register.
Did you miss your activation email?
Fri, 21. December 2007 - 08:53:47

Login with username, password and session length
Search:     Advanced search
Please register with your real name and do not post any SPAM! Violations: "Hk." and "Getagrip" => deleted
1.459 Posts in 346 Topics by 21 Members
Latest Member: Tim81
* Home Help Search Login Register
+  vLIB
|-+  English support
| |-+  vlibTemplate, vlibMimeMail, vlibDate
| | |-+  output arrays
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: output arrays  (Read 736 times)
BM
Guest
on: Wed, 13. August 2003 - 18: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:

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:

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.
Logged
Yaslaw Kowalejeff
Guest
Reply #1 on: Thu, 14. August 2003 - 10:34:54

1 Array more and then it works...

Code:
Array



   b0=Array cat= 'Jackets',

                subcat = Array

        

            0 = Array

                

                    id = 4

                    strSubCategory = PC

                


In the Template_


Code:
tmpl_loop menu

  tmpl_var cat

  tmpl_loop subcat

    tmpl_var id tmpl_var strSubCategory

  /tmpl_loop

/tmpl_loop
Logged
releasedj
Guest
Reply #2 on: Thu, 14. August 2003 - 11:15:10

Try this:

Code:

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
Logged
BM
Guest
Reply #3 on: Thu, 14. August 2003 - 14: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:

$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.
Logged
releasedj
Guest
Reply #4 on: Thu, 14. August 2003 - 16:23:24

Try this. It uses the loop functions that enable you to build a loop more intuitively.

Code:

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.
Logged
BM
Guest
Reply #5 on: Thu, 14. August 2003 - 17: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
Logged
releasedj
Guest
Reply #6 on: Thu, 14. August 2003 - 18:04:15

No problem. Glad to have been of help.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!