Ok - I got this to work like so, first the php bit

require_once('smarty-inc.php');

$array1[0] = array
        (
            'sid' => 10,
            'domain' => 'http://www.sample.com',
            'name' => 'Sample',
        )
;



$array2[10] = array
        (
            0 => array
                (
                    'network_id' => 3
                ),

        1 => array
            (
                'network_id' => 1
            )
    );

$sm->assign_by_ref('array1', $array1);
$sm->assign_by_ref('array2', $array2);

$sm->display('helpguy.tpl');

And used this as the template

{foreach from=$array1 key=key item=sites}
	{$sites.name}<br />
	{$sites.domain}<br />
	{foreach from=$array2[$sites.sid] key=k2 item=networks}
		netid = {$networks.network_id}<br />
	{/foreach} 	
{/foreach}

If it doesn't work use [man]var_export[/man] to print out some of your array, as the biggest pain here was editing it back to usable code. EDIT: I've put keys in those foreaches, they're of no use, but I did it out of habit.

    It works!! Thank you, however one more problem is left.

    The network_id it only displays the first character ... how can I make it display the whole number (or string if i decide to use strings in there as well) ?

    Thanks again!!

      Well in the data in the array the network id is only one character, 1 or 3. If you want strings just change them to strings in the array. It should be perfect as it is. Remember to mark this resolved with the thread tools when you're happy with it.

        The problem is that the array does hold strings, when it says "None" it still prints only 'N' -- its a wierd problem ...

        Since the majority of my problem is fixed, I guess the problem is resolved, but I want to see if anyone can help out with this minor thing before marking the thread done.

        Thanks!

          //Off-topic

          None of that looks like any PHP code I grew up with...what is "smarty"?

          //End off-topic

            LoganK wrote:

            //Off-topic

            None of that looks like any PHP code I grew up with...what is "smarty"?

            //End off-topic

            http://smarty.php.net/

            I never heard of it until this post.

              If you change network section of the array to

              $array2[10] = array
                      (
                          0 => array
                              (
                                  'network_id' => 'Three three - that be me: 3'
                              ),
              
                      1 => array
                          (
                              'network_id' => 'One one - you see me: 1'
                          )
                  );

              Then it works completely right, or have you having trouble with strings elsewhere?

              Logan, lth2h - at first I really avoided Smarty thinking it can't be as fast as coding php by hand, but if you use its caching features you'll end up with pages loading 10 times quicker, often completely avoiding having to contact a database to generate page content. Plus in the project I'm currently working on a centralised site is giving away mini cashback sites drawing data from a central server. I allow the user to totally customise the look of the site by uploading a zipped skin packs that gets scanned so it's only got images / flash / javascript and template files so they can have 100% flexibility in the site's look. The pages are cached for an hour each reducing the db connection load to next to nothing, and if you change the skin all the caches are flushed. Each subsite's location is also kept in a database so if a critical change is made on the master site, such as the removal of an advert that really must be gone straight away then all a cache kill script is called on each one.

              And the great thing is I don't have to create the user manual to tell them how to create pages as it's already out there. I just have to tell them what data is available.

              Obviously for some projects it's not necessary, but for this it's staggering - plus your php scripts look great when they go nowhere near any HTML.

                lth2h wrote:

                http://smarty.php.net/

                I never heard of it until this post.

                Neither had I.

                Drakkla - I'll take your advice and, after learning smarty, see if I can't use it in my apps.

                  Drakla,
                  When I run a substitution with strings for numbers, the array looks like

                  
                  Array
                  (
                      [10] => Array
                          (
                              [0] => Network 
                              [1] => Another Network        )
                  
                  [13] => Array
                      (
                          [0] => None
                      )
                  )
                  
                  

                  but the print out is

                  N (etwork)
                  A (nother network)
                  N (one)

                  so the loops is right, but why is the string truncated? Any ideas?

                    It's because you've changed your array format and got rid of the network_id key. So now all you have to do is change the line

                    netid = {$networks.network_id}<br />

                    to
                    netid = {$networks}<br />

                    I've checked it, and it's working. Just remember if you change your data array format you're also going to have to change the template.

                      ouch that was stupid of me ... thats what you get for coding at 2AM ... thank you very much for your help!

                        Write a Reply...