웹 응용 프로그램에서 작업 중이므로 조금 더 코드를 개선하고 싶습니다. (가입 또는 무엇 이건?) 선택 PHP에서 쉬운 방법이 있나요 특정한 하나의 정보 :SQL에서 세 개의 테이블을 선택하고 PHP 배열에 저장
이제
내 질문 :
이
내가 응용 프로그램을 위해 만들어진 SQL 테이블 구조 event_id를 저장하고 그 구조를 따라 배열에 저장하십시오. 예를 들면$events = array(
'event_id' => 1,
'event_name' => '{"de":"Weltwirtschaftsforum","fr":"Forum \u00e9conomique mondial","it":"Forum Economico Mondiale"}',
'event_description' => '{"de":"Description DE","fr":"Description FR","it":"Description IT"}',
'event_lastedit' => 2011-12-01 10:23:35,
'locations' => array(
array(
'location_id' => 1,
'location_name' => 'Bern',
'location_date' => '01.01.2012',
'location_deadline' => 1323340607,
'timestamps' => array(
array(
'timestamp_id' => 1,
'timestamp_time' => '10:30',
'timestamp_seats' => 30
),
array(
'timestamp_id' => 2,
'timestamp_time' => '16:30',
'timestamp_seats' => 40
)
)
),
array(
'location_id' => 2,
'location_name' => 'Davos',
'location_date' => '02.02.2012',
'location_deadline' => 1323340607,
'timestamps' => array(
array(
'timestamp_id' => 3,
'timestamp_time' => '12:30',
'timestamp_seats' => 50
),
array(
'timestamp_id' => 4,
'timestamp_time' => '15:30',
'timestamp_seats' => 60
)
)
)
)
);
질문이 충분히 명확하기를 바랍니다.
인사말 Spinne
편집 : 내가 지금까지 무슨 짓을 :
$event = $event_db->querySingle("SELECT * FROM rf_events WHERE event_id={$event_id}", true)
$rf_locations = $event_db->query("SELECT * FROM rf_locations WHERE event_id={$event_id}");
$locations = array();
$timestamps = array();
$counter = 0;
// Loop sql query result and save entries in $events array.
while ($row = $rf_locations->fetchArray()){
$locations[$counter] = array(
'location_id' => $row['location_id'],
'location_name' => json_decode($row['location_name'], true),
'location_date' => $row['location_date'],
'location_deadline' => $row['location_deadline']
);
$rf_timestamps = $event_db->query("SELECT * FROM rf_timestamps WHERE location_id={$row['location_id']}");
$counter2 = 0;
while ($row2 = $rf_timestamps->fetchArray()){
$locations[$counter]['timestamps'][$counter2] = array(
'timestamp_id' => $row2['timestamp_id'],
'timestamp_time' => $row2['timestamp_time'],
'timestamp_seats' => $row2['timestamp_seats']
);
$counter2++;
}
$counter++;
}
네, 가능합니다, 당신은 JOINSs이 그것을 할 수있는 올바른 방법입니다 그 권리입니다. 어떤 MySQL 라이브러리를 사용하고 있습니까? 지금까지 시도한 코드의 예가 있습니까? –
PHP (http://php.net/manual/de/book.sqlite3.php)에서 SQLite3 핵심 라이브러리를 사용하고 있습니다. 지금까지 나는 id에 의해 선택을하고 중첩 된 while-loops를 생성하고 배열에 정보를 푸시했습니다. – Spinnenzunge
게시물을 수정하여 지금까지 작성한 코드를 표시하십시오. –