Tom V Posted August 26, 2020 Share Posted August 26, 2020 Has anyone created a form like in this example? Table1 and Table2 have a one to many relationship, submitted data stored in Table3. It seems you should just be able to use {#each id} {#each option} {/each} {/each}, but that doesn't work. Anyone have any friendly advice for me? Quote Link to comment Share on other sites More sharing options...
Sim Posted August 26, 2020 Share Posted August 26, 2020 I have not been able to use nested loops in GL. I'm not sure if the template system supports it Quote Link to comment Share on other sites More sharing options...
Dayo Posted August 27, 2020 Share Posted August 27, 2020 $tables = array( array( "name" => "table 1", "options" => array( array( "value" => 1, "text" => "option 1", "name" => "table1"), array( "value" => 2, "text" => "option 2", "name" => "table1"), array( "value" => 3, "text" => "option 3", "name" => "table1") ) ), array( "name" => "table 2", "options" => array( array( "value" => 1, "text" => "option 1", "name" => "table2" ), array( "value" => 2, "text" => "option 2", "name" => "table2" ), array( "value" => 3, "text" => "option 3", "name" => "table2" ) ) ), array( "name" => "table 3", "options" => array( array( "value" => 1, "text" => "option 1", "name" => "table3"), array( "value" => 2, "text" => "option 2", "name" => "table3"), array( "value" => 3, "text" => "option 3", "name" => "table3") ) ) ); $this->page->buildElement("tables", array( "tables" => $tables )); {#each tables} <h1>{name}</h1> {#each options} <input type="radio" value="{value}" name="{name}[]" /> {text} {/each} {/each} Try something like this 3 Quote Link to comment Share on other sites More sharing options...
Tom V Posted September 23, 2020 Author Share Posted September 23, 2020 I tried to follow your example, but i can't seem to get nested each's to work. For example, let's look at garage module. If I want a table to look like this: Location = England Car 1 Car 2 Location = France Car 3 I tried this but it doesn't give me the expected result. $cars[] = array( "locname" => $loc->L_name, "options" => array( "name" => $car->CA_name, "location" => $loc->L_name, "damage" => $car->GA_damage.'%', "id" => $car->GA_id, "value" => number_format($value) ), array( "locname" => $loc->L_name, "options" => array( "name" => $car->CA_name, "location" => $loc->L_name, "damage" => $car->GA_damage.'%', "id" => $car->GA_id, "value" => number_format($value) ) ) ); } $this->html .= $this->page->buildElement('garage', array("cars" => $cars)); <tbody> {#unless cars} <tr> <td colspan="5"> <div class="text-center"> <em> You have no cars</em> </div> </td> </tr> {/unless} {#each cars} <h1>{locname}</h1> {#each options} <tr> <td>{name}</td> <td>{damage}</td> <td>${value}</td> <td>{location}</td> <td class="text-center"> <a href="?page=garage&action=sell&id={id}">Sell</a> <a href="?page=garage&action=crush&id={id}">Crush</a> <a href="?page=garage&action=repair&id={id}">Repair</a> </td> </tr> {/each} {/each} </tbody> Quote Link to comment Share on other sites More sharing options...
Dayo Posted September 24, 2020 Share Posted September 24, 2020 @Tom V Options is a flat array, it needs to be an array of arrays if that makes sense "options" => array( array( "name" => "Car 1", // ... ), array( "name" => "Car 2", // ... ), ) <?php $locations = $this->db->selectAll("SELECT L_name as 'name', L_id as 'id' FROM locations"); foreach ($locations as $key => $location) { $locations[$key]["options"] = $this->db->selectAll("SELECT * FROM garage WHERE G_location = :loc", array( ":loc" => $location["id"] )); } Quote Link to comment Share on other sites More sharing options...
Sim Posted September 25, 2020 Share Posted September 25, 2020 I've never been able to get nested arrays to work to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.