数据库查询结果构建多维数组
我想将前面数据库查询出来的结果构建一个多维数组,数据库查询出来的第一个结果对应第一层嵌套,第二个结果对应第二层嵌套,如何做,事先声明我是菜鸟,请多指点
<br /> // 查询变量<br /> <br /> $sql1 = "select remark,name from arp_careset where typegroup ='dissect-position' order by id"; <br /> $rs1 = mysql_query($sql1); <br /> <br /> while($r1 = mysql_fetch_assoc($rs1)) <br /> { echo $r1['name']; <br /> <br /> $sql = "select group_concat(name) as name from arp_careset where typegroup <>'dissect-position' and typegroup like '%".$r1["remark"]."%' order by id";<br /> $rs = mysql_query($sql); <br /> <br /> while($r = mysql_fetch_array($rs)) <br /> { $ar = explode(',', $r['name']); <br /> echo join(' ', $ar); <br /> } }<br /> //构建数组<br /> <br /> $mem = array(<br /> array<br /> (<br /> lang_show(''),<br /> array<br /> (<br /> // 嵌套开始<br /> array(<br /> lang_show('account_manager'),<br /> //第二层嵌套<br /> array(<br /> 'group_list.php,1',<br /> )<br /> //第二层嵌套结束 <br /> ),<br /> // 嵌套结束<br /> ) <br /> ),<br /> );
$rs = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, remark from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='dissect'");<br /> while($r = mysql_fetch_assoc($rs)) {<br /> echo $r['name']. '<br />';<br /> $rs1 = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, remark from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='$r[secondary]' and SUBSTRING_INDEX(typegroup,'-',-1) = '$r[remark]'");<br /> while($r = mysql_fetch_assoc($rs1)) {<br /> echo $r['name'] . ' ';<br /> }<br /> echo '<br />';<br /> }
$res = array(); //这是结果数组<br> $rs = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, remark from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='dissect'");<br> while($r = mysql_fetch_assoc($rs)) {<br> $tmp = array(); //初始化一个临时数组<br> $rs1 = mysql_query("select name, SUBSTRING_INDEX(typegroup,'-',-1) as secondary, remark from arp_careset where SUBSTRING_INDEX(typegroup,'-',1)='$r[secondary]' and SUBSTRING_INDEX(typegroup,'-',-1) = '$r[remark]'"); <div class="clear"> </div>