Ask: How to build a multidimensional array of SQL query results
The function I want to implement is this:
I pass a string of numbers for SQL to receive, the number in the form of the ID value of the dish, similar to "one-in-one," after the query can be changed into a multi-dimensional array according to the dishes.
First question, how do I get this string out of the way and loop through the SQL query and save all the results?
PHP Code
$s = $ids;//ID string received
SQL Code
$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);
This SQL is based on a certain ID of the menu to query the details of the dishes, if you save the string ID of all the menu information?
The second question, which holds the array of results after the full ID query, becomes the following multidimensional array form
PHP Code
$a =array ("2" = = Array ("1" = = Array ("id" = 728, "Name" = "Jade belt sesame oil Lettuce", "Preprice" and "favprice" = 68, "Pic" = jdcpic1342685874.jpg, "num" = 1, "ts" = 0, "FJ" + "" ")," 2 "= = Array (" id "= 727, "Name" and "The New Hang Fish," "Preprice" and "favprice" = 38, "Pic" = jdcpic1342685755.jpg, "num" = 1, "ts" = 0, "FJ" + ")", "1" = = Array ("1" = = Array ("id" = 749, "name" and "20" in Japan, "Preprice" 888,"Favprice" = 888, "pic" = jdcpic1342688648.jpg, "num" = 5, "ts" = 0, "FJ" + "" ")," 2 "= = Array ( "id" = 748, "name" and "Original juice slow boiled braised middle-eastern dried abalone," preprice "= 788, "Favprice" = 788, "pic" = jdcpic1342688600.jpg, "num" = 1, "ts" = 0, "FJ" + "" ")," 3 "= = Array ("id" = 747, "name" and "soy" fried chicken with chili sauce, "preprice" = 20, "Favprice", "pic" = jdcpic1342688515.jpg, "num" = 1, "ts" = 0, "fj" = "")));
In the above code, the outermost 2 and 1 represent the classification of the Food category, the dimension is not fixed, it may be a classification, or it may be in four or five categories,
The second is the number of the dish, the automatic, the final value is the information of the dishes.
How to modify. Using the above SQL, you can finally generate an array with the same structure as the following multidimensional array?
Also hope high finger teach, thank you!
------Solution--------------------
1: $array _veginfo= $query _veginfo->fetch (2); you change this 2 to 0 or 10000 to see what it is, it is best to see how it is achieved, I suspect 2 is the total number of bars, under normal design, 0 should be unlimited
2:
echo "
";
Print_r ($array _veginfo);