Heim >Backend-Entwicklung >PHP-Tutorial >请问:怎么将sql查询结果生成多维数组
请教:如何将sql查询结果生成多维数组
我想实现的功能是这样的:
我传递一串数字供sql接收,数字的形式是菜品的ID值,类似“1,2,3,”,经过查询可以变成根据菜品分类而来的多维数组。
第一个问题,我如何将这个字符串分离开后循环利用sql查询并保存全部结果呢?
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$s=$ids;//接收到的ID字符串
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$sqlslt_veginfo="select {$tb_veg}.veg_id,{$tb_veg}.vsort_id,{$tb_veg}.veg_name,{$tb_veg}.veg_preprice,{$tb_veg}.veg_favprice,{$tb_veg}.veg_picstr,{$tb_veg}.veg_ptfs,{$tb_veg}.veg_ts,{$tb_veg}.veg_fj from {$tb_veg} where {$tb_veg}.veg_id='{$s}'and {$tb_veg}.vdel_vfy='0'";$query_veginfo=$pdodb->query($sqlslt_veginfo);$array_veginfo=$query_veginfo->fetch(2);
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$a=array( "2" => Array ( "1" => Array ( "id" => 728, "name" => "玉带香油莴笋", "preprice" => 68, "favprice" => 68, "pic" => jdcpic1342685874.jpg, "num" => 1, "ts" => 0, "fj" => "" ), "2" => Array ( "id" => 727, "name" => 新杭帮熏鱼, "preprice" => 38, "favprice" => 38, "pic" => jdcpic1342685755.jpg, "num" => 1, "ts" => 0, "fj" => "" ) ), "1" => Array ( "1" => Array ( "id" => 749, "name" => 秘制日本二十头极品鲍鱼, "preprice" => 888, "favprice" => 888, "pic" => jdcpic1342688648.jpg, "num" => 5, "ts" => 0, "fj" => "" ), "2" => Array ( "id" => 748, "name" => 原汁慢煮焖煨中东干鲍鱼, "preprice" => 788, "favprice" => 788, "pic" => jdcpic1342688600.jpg, "num" => 1, "ts" => 0, "fj" => "" ), "3" => Array ( "id" => 747, "name" => 炝椒酱爆嫩鸡丁, "preprice" => 20, "favprice" => 20, "pic" => jdcpic1342688515.jpg, "num" => 1, "ts" => 0, "fj" => "" ) ));
";<br>print_r($array_veginfo);<div class="clear"> </div>