Welcome Guest, Not a member yet? Register   Sign In
Nested tabs
#1

[eluser]Hoopoe[/eluser]
Hi, I have a page with tabs.

The tabs are nested, and the markup for them is generated dynamically.

At the moment it's written in ordinary procedural php. I am trying to move it over to CI.

My question is about a key part of the existing code which I want to replicate in CI. Basically, in this section of code I nest a query within a while clause used to loop over results from another query.

From my experience of CI, that sort of looping is done in a view, whereas a query is done in the model. This is what bothers me.

Any thoughts or guidance gratefully received.

Tom


Code:
<?php
        
        $queryall2 = "select distinct pcat, pcatid from pcategory inner join projects on pcatid = projcat order by pcat desc";
        $resultall2 = mysql_query ( $queryall2) ;
        
                while ($row2 = mysql_fetch_assoc ($resultall2))
        { ?>
            
            <div id="fragment-&lt;?php echo $row2['pcatid'];?&gt;" style="background-color: #F2F3F5";>
    <ul>
        
        &lt;?php    $jobcat=$row2['pcatid'];
                $queryall3 = "select projid, projtit, projcost, projdate from projects where projcat= '$jobcat'";
                $resultall3 = mysql_query ( $queryall3 ) ;
                while ($row3 = mysql_fetch_assoc ($resultall3))
            { ?&gt;
                <li><a href= "#fragment-&lt;?php echo $row3['projid']?&gt;a"><span>&lt;?php echo $row3['projtit']; ?&gt; </span></a></li>
            
                
     &lt;?php     } ?&gt;
                
    </ul>
#2

[eluser]toopay[/eluser]
Process the query in model, to generates multi dimensional array, then passed it to view via controller. Extract that values in your view, with nested foreach or while statement.
#3

[eluser]Hoopoe[/eluser]
Thank you: I think I get it. Do a query wh returns all the data wanted - do a foreach loop for the li elements, and foreach foreach loop for the divs

Ok haven't tried it yet but now have a direction.

Tom




Theme © iAndrew 2016 - Forum software by © MyBB