Welcome Guest, Not a member yet? Register   Sign In
Fetching related tables
#4

[eluser]Jaketoolson[/eluser]
You could create the query and set the $vars in one loop, then run another loop to create the code.

Code:
$sql="SELECT id.c, id.name, title.p FROM Categories c
INNER JOIN Posts p ON p.category_id = c.id";
foreach ($query->result() as $row)
{
    $cat_id = $row->id;
    $post_title = $row->title;
    
    $datas[$cat_id][] = $post_title;
}

foreach ($datas as $key)
{
    echo '<div id="cat_'.key($key).'">';
    foreach ($key as $k => $v)
    {
        echo '<p>'.$v.'</p>';
    }
    echo '</div>';
}


Messages In This Thread
Fetching related tables - by El Forum - 02-18-2011, 04:24 PM
Fetching related tables - by El Forum - 02-18-2011, 05:11 PM
Fetching related tables - by El Forum - 02-19-2011, 06:11 AM
Fetching related tables - by El Forum - 02-20-2011, 02:31 PM
Fetching related tables - by El Forum - 02-20-2011, 04:43 PM
Fetching related tables - by El Forum - 02-20-2011, 07:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB