Database query results build multidimensional arrays
I want to put the results of the previous database query to build a multidimensional array, the first result of database query corresponding to the first level of nesting, the second result corresponding to the second level of nesting, how to do, in advance declare I am a rookie, please more guidance
Query variables
{Echo
$sql = "Select Group_concat (name) as name from Arp_careset where Typegroup <> ' dissect-position ' and typegroup like ' % ". $r 1[" Remark "]." % ' order by ID ';
} }
Building an array
$mem = Array (
Array
(
Lang_show ("),
Array
(
Nesting start
Array
Lang_show (' Account_manager '),
Second level nesting
Array
' group_list.php,1 ',
)
Second level nesting end
),
Nesting End
)
),
);
------Solution--------------------
Your data organization has brought a lot of inconvenience to your reading.
Write like this
$rs = mysql_query ("Select Name, Substring_index (Typegroup, '-', -1) as secondary, remark from Arp_careset where substring_i Ndex (Typegroup, '-', 1) = ' dissect ');
while ($r = Mysql_fetch_assoc ($rs)) {
echo $r [' name ']. '
';
$rs 1 = 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] ' ");
while ($r = Mysql_fetch_assoc ($rs 1)) {
echo $r [' name ']. ' ';
}
Echo '
';
}
Surface
Nutritional status secretion by hair skin eye/orbital limbs/tail mammary gland external genitalia anus
Lymph node
axillary lymph node neck lymph node inguinal lymph node pulmonary lymph node intestinal lymph node
Head and neck
Eyelid/cornea/pupil teeth/gum ear/nasal meninges/whole brain skull salivary glands esophageal trachea thyroid
Chest
Thoracic diaphragm/mediastinal heart aortic arch Lung and bronchus
Abdominal
Abdominal mesenteric spleen Pancreas kidney
------Solution--------------------
Why is it that the data is poorly organized?
The primary grouping Typegroup contains two categories of information
and by "adjacency list algorithm" should contain only one category of information
From your data, you need to typegroup, remark two fields to uniquely confirm the attribution of a representation
This is actually the adjacency list algorithm.
Although you can now use the Substring_index function to split the Typegroup to get the category information
But the Substring_index function is MySQL proprietary. If, for some reason, the database system is replaced later, the code modification is too large.
Although you can hand over the split work to PHP, many like will reduce query efficiency
The program also appears to be more bloated
------Solution--------------------
Create a multidimensional array diagram
$res = Array ();//This is the result array
$rs = mysql_query ("Select Name, Substring_index (Typegroup, '-',-1) As secondary, remark from Arp_careset where Substring_index (Typegroup, '-', 1) = ' dissect ' ");
while ($r = Mysql_fetch_assoc ($rs)) {
$tmp = array ();//Initialize a temporary array
$rs 1 = 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] ' ");