안녕하세요, 최종 배열 결과가이 json 배열처럼 보이는 연관 배열을 쿼리하려고합니다. 그러나 데이터 섹션과 ID 이름 섹션을 한 번만 쿼리하면 모든 노드와 인접성 섹션에 여러 번 쿼리 할 수 있습니다. 노드에 여러 개의 인접성이있는 경우 조건이 충족되면이 중첩 된 배열의 한 섹션을 한 번 이상 쿼리하는 방법 이 struture를 유지하면서 노드에 대한 다중 또는 없음 인접성을 유지하면서 한 번 만난 적이 있습니까?중첩 된 연관 배열에서 데이터베이스 문제 쿼리
var json =[{
"adjacencies": [{
"nodeTo": "graphnode9",
"nodeFrom": "graphnode5",
"data": {}
}],
"data": {
"$color": "#C74243",
"$type": "triangle",
},
"id": "graphnode5",
"name": "graphnode5"
}];
여기 내 데이터베이스 구조
nodes Relationships
----- -------------
id int(11), id int(11),
name varchar(35), to int(11), //this is the destination node from the id relation
color varchar(7), data varchar(0) null
type varchar (12), Foreign key (id) references nodes(id)
Primary key (id)
engine = innodb
여기에 연관 배열을 점점에서 내 시도는하지만 한꺼번에 조회 전체 strucute 중복입니다. 당신은 루프 외부에서 배열을 생성하고
$array = array();
while($row=$result->FetchRow()) {
$array[] = array(
"adjacencies:" => array(
"nodeTo" => (float)$row['to'],
"nodeFrom" => (float)$row['id'],
"data" => array()
),
"data" => array(
'$color' => $row['color'],
'$type' => $row['type']
),
"id" => (float)$row['id'],
"name" => $row['name']
);
}
무엇 당신의 결과 배열이 생겼에 항목을 추가 할 필요가
–@jcubic lol을 편집하려고했습니다. –
결과 배열은 다음과 같습니다 : Array ([adjacencies :] => Array ([nodeTo] => 2 [nodeFrom] => 1 [data] => Array()) [데이터] => 배열 ([$ color] => # 83548B [$ type] => circle) [id :] => 1 [name :] => Blue Jay) 괜찮 았지만 조건을 충족 시키더라도 adjacencies 내의 배열에 두 번 이상 쿼리하려고하지만 더 많은 인접성을 제외하고는 전체 구조를 그대로 유지합니다 – user1902588