嵌套的foreach循环和交叉变量

I'm new in this so please have patience with me (even when I know that's no excuse)

I have a problem with a nested foreach loop (knowing that nested foreach loop aren't recommended but only way I could though of doing it).

I have two tables "categories" and "section" where each section have a categories that own them. I try to call each category thru a foreach loop and inside each one another foreach loop where the sections with that category given where called, just like this (not actual code because I speak Spanish and have a lot of therm in my language and I have use functions of a separate file, but something alike)

Foreach($category as $category){
    echo category;

       Foreach (getsection(section[category] = category) as section){
           Echo section;
       }
}

Edit: sorry, my bad the question is that the categories are showed but the sections aren't and I can't find why, it doesn't go whit arrays but with MySQL tables using the same function to fetch the data from two different tables (correctly separated) so the error have to be in the nesting somehow.

2ºedit: so for avoiding more errors, here is my actual script:

    <?php
        foreach (tomarcategorias() as $order =>$categorias){
            $name = $categorias['name'];
            $id = $categorias['id'];
            $order =$categorias['order'];

            $prev = tomarcategoria('order', ($order-1));
            $next = tomarcategoria('order', ($order+1));

            ?>

            <tr>

            <td  style="padding-right: 10px; text-align: center;"><?php echo $categorias['order'], '<br>'; ?></td>

            <td style="padding-left: 10px; border-right:none;"><?php echo $categorias['name'], '<br>'; ?></td>

            <td style="border-left:none;">

                <a href="downupcat.php?actyon=up&id=<?php echo $categorias['id'];?>&prev=<?php echo $prev['id'];?>"><img src="img/iconos/up.png" alt="subir" height="14" width="14"></a>                                <a href="downupcat.php?actyon=down&id=<?php echo $categorias['id'];?>&next=<?php echo $next['id'];?>"><img src="img/iconos/down.png" alt="bajar" height="14" width="14"></a> 
                <a href="deletecat.php?id=<?php echo $categorias['id'];?>"><img src="img/iconos/borrarcerrar.png" alt="borrar" height="14" width="14"></a>
            </td>
            <?php
            foreach(tomarsecciones() as $secciones){
            ?>
            <tr>
                <td><?php echo $secciones['name'];?></td>
            </tr>
            </tr>
    <?php
        }
        }

4ºedit: (don't know how to put this below, and just hope to making it right...

Ian, I made the change, didn't actually see it before but didn't change anything in the end anyway, thank obviously for showing me the tipo. made a little change on this, i forgot to put the cross data and value on the script the first(actually third) time, make it like this:

            foreach(tomarsecciones('idcategoria', $id) as $secciones){

and just in case the script for the function is next, but i use the same for categories and it works just fine, it's in sections where it all gone bad:

function tomarsecciones($data, $value){

$secciones = array();

$query = mysql_query("SELECT `id`, `name`, `order`, `idcategoria` FROM `secciones` ORDER BY `order` WHERE `$data` = '$value'");

while($row = mysql_fetch_assoc($query)){
    $secciones[]=$row;

}
return $secciones;

}

well well well, my (noobie) mistake. The error was in deed in the function mysql call, looks that the call or "order" must go by law after the "where" so where my query was:

$query = mysql_query("SELECT `id`, `name`, `order`, `idcategoria` FROM `secciones` ORDER BY `order` WHERE `$data` = '$value'");

it worked with:

$query = mysql_query("SELECT `id`, `name`, `order`, `idcategoria` FROM `secciones` WHERE `$data` = '$value' ORDER BY `order`");

i know that nobody seem to care for it, must if anybody look for this in future it might be for some use.