开发者

How to take out the first part of array?

The following function out-puts an array and html.

I don't want to have

<li><a href="http://127.0.0.1/ci_okadadesign/index.php/admin/menus/r">r</a></li>

Could anyone tell me how to achive it please?

Function

function getTopMenus(){
     $data[0] = 'root';
     $this->db->where('parentid',0);
     $Q = $this->db->get('menus');
     if 开发者_如何学Python($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
 }

print_r():

Array (
    [0] => Array (
            [id] => 24
            [name] => Main menu
            [shortdesc] => mainmenu
            [status] => active
            [parentid] => 0
        )
    [1] => Array (
            [id] => 25
            [name] => Galleri 1
            [shortdesc] => galleri1
            [status] => active
            [parentid] => 0
        )
)

HTML:

<li><a href="http://127.0.0.1/ci_okadadesign/index.php/admin/menus">menus</a>
  <ul>
    <li><a href="http://127.0.0.1/ci_okadadesign/index.php/admin/menus/r">r</a></li>
    <li><a href="http://127.0.0.1/ci_okadadesign/index.php/admin/menus/mainmenu">Main menu</a></li>
    <li><a href="http://127.0.0.1/ci_okadadesign/index.php/admin/menus/galleri1">Galleri 1</a></li>
  </ul>


Looks like you have a bunch of menu items defined in your database. If there's a menu item in there titled 'r' all you have to do is delete that row and that <li> will go away.


array_shift() is what you want


Are you using CodeIgniter? You can refine the query saved in $Q using get_where instead of get (see CodeIgniter User Guide).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜