vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   nested dependent vb:each - building headers for sorting (https://vborg.vbsupport.ru/showthread.php?t=281318)

wpeloquin 04-09-2012 02:25 PM

nested dependent vb:each - building headers for sorting
 
1 Attachment(s)
Hello,

I have tried numerous ways, but am beginning to think this not possible (or i'm just stuck looking at it from a single angle), so figured i'd try to get some outside opinions/help.

In my php file, i create an array that looks like the following:
Code:

    while ($wp_alist = $vbulletin->db->fetch_array($wp_fulllist))
    {
        $wp_list[$count] = array(
            'id' => htmlspecialchars($wp_alist['id']),
            'name' => htmlspecialchars($wp_alist['name']),
            'locid' => htmlspecialchars($wp_alist['locid']),
            'location' => htmlspecialchars($wp_alist['location']),
            'url' => htmlspecialchars($wp_alist['url'])
        );
        $count++;
    }

    $templater->register('wp_list', $wp_list);

In my template, i can successfully display the entire list using
Code:

<vb:each from="wp_list" value="list">
<tr>
        <td>{vb:raw list.location}</td>
        <td><a href="{vb:raw list.url}">{vb:raw list.name}</a></td>
</tr>
</vb:each>

However, what i would like to do is separate the items based on the location, something similar to the image that i attached. A rough code might be something like this, but i know that vb:raw cannot be used in a conditional, and i cannot figure out how to work around this.
Code:

<vb:each from="wp_list" value="location">
<h1>{vb:raw location.location}</h1>
        <vb:each from="wp_list" value="list">
        <vb:if condition="{vb:raw loc.location} = {vb:raw scroll.location}">
        <tr>
                <td>{vb:raw list.location}</td>
                <td><a href="{vb:raw list.url}">{vb:raw list.name}</a></td>
        </tr>
        </vb:if>
        </vb:each>
</vb:each>


kh99 04-09-2012 03:24 PM

I think that appraoch will work but you might need to create your own array of locaitons and register it too. Maybe try something like this:

Code:

    while ($wp_alist = $vbulletin->db->fetch_array($wp_fulllist))
    {
        $locations[] = htmlspecialchars($wp_alist['location']);
        $wp_list[] = array(
            'id' => htmlspecialchars($wp_alist['id']),
            'name' => htmlspecialchars($wp_alist['name']),
            'locid' => htmlspecialchars($wp_alist['locid']),
            'location' => htmlspecialchars($wp_alist['location']),
            'url' => htmlspecialchars($wp_alist['url'])
        );
    }
    $locations = array_unique($locations);
    $templater->register('wp_list', $wp_list);   
    $templater->register('wp_locations', $locations);


and then in your template:

Code:

<vb:each from="wp_locations" value="location">
<h1>{vb:raw location}</h1>
        <vb:each from="wp_list" value="list">
        <vb:if condition="$list['location'] == $location">
        <tr>
                <td>{vb:raw list.location}</td>
                <td><a href="{vb:raw list.url}">{vb:raw list.name}</a></td>
        </tr>
        </vb:if>
        </vb:each>
</vb:each>


I'm not sure of there's any way to use the value from the outer vb:each to specify the inner vb:each array. That would make things a little more efficient.

wpeloquin 04-10-2012 06:32 PM

That didn't work (for me, anyways). I think it still sees the objects in the IF statement as <vb:raw> statements...

kh99 04-11-2012 01:46 AM

I did have one error in the code above, which I just fixed. It said location.location when it should just be location. Also I left out the htmlspecialchars when setting the locations array. But I did test it and it basically seemed to work. What happens when you try?

wpeloquin 04-13-2012 07:07 PM

I had to play with the <table> tag and it is working now (see below). Much thanks kh99! I was on the right track it seems, just off on the syntax. You saved me many hours of tedious hair pulling :)

Code:

<vb:each from="wp_locations" value="location">
<h1>{vb:raw location}</h1>
<table>
        <vb:each from="wp_list" value="list">
        <vb:if condition="$list['location'] == $location">
        <tr>
                <td>{vb:raw list.location}</td>
                <td><a href="{vb:raw list.url}">{vb:raw list.name}</a></td>
        </tr>
        </vb:if>
        </vb:each>
</table>
</vb:each>



All times are GMT. The time now is 12:15 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02530 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete