English 中文(简体)
下降男子数据阵列
原标题:An array for data of dropdown menu

有一些想法认为,从Xml或json的数据中产生一种下降的菜单。 但是,我怎么能够完全与营地打交道? 一种可能的方法是建立一个多层次阵列。 但是,从我的ql数据(使父母亲为补贴,以及如何有效地阅读阵列(通过 lo子吗?)中产生这种说法的最佳途径是什么?

最佳回答

<>strong>php>side,请请在座标上以各种形式检索:

$menu = array(
    page/1  =>  about ,
    page/2  =>  photos ,
    menu-title  =>  array( page/4  =>  sub-menu-1 , page/5  =>  sub-menu-2 )
);

echo  <ul> ;
foreach($menu as $key => $value){
  if(is_string($value)){
     echo  <li><a href=" .$key. "> .$value. </a></li> ;
  }
  if(is_array($value)){
    echo  <ul> ;
    echo  <li><a href="#"> .key($value). </a></li> ;
    foreach($value as $sub_key => $sub_value){
      echo  <li><a href=" .$sub_key . "> .$sub_value. </a></li> ;
    }
    echo  </ul> ;
  }
}
echo  </ul> ;

for mysql database, have a column of "parent_id" if it is null then it would be a root level, other than that, it would be a sub there, another column of "path" and "title,you can add a "weight" column as well to order them.

<>strong>NOTE:这是未经测试的代码。

问题回答

我愿通过从我sql中抽出的几行,并建立一个阵列,关键是投入的价值,其价值是案文。 因此,如果你想像:

<input value="UT">Utah</input>
<input value="VT">Vermont</input>
<input value="NV">Nevada</input>
<input value="CA">California</input>

我将建立这样的阵列:

array(

       "UT" => "Utah",
       "VT" => "Vermont",
       "NV" => "Nevada",
       "CA" => "California",
)

It s very easy to translate the array into the html using a foreach.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签