私は最初の2つが基本情報を保持し、最後の2つはプロパティと画像を保持する複数のテーブルから集めたデータを出力するサイトに取り組んでいます。現在、私はテーブルと出力の値を返すいくつかのコード行を通して作業しています最後にhtmlに追加するときに表示する必要があるデータです。私が抱えているいくつかの問題は、私が理解しているレプリケーションの問題です。内側のジョイントの領域です。私のPHPファイルは、ある程度の複製をフィルタリングしていますが、私が作ろうとしている2つの配列のうちで失敗し、イメージ配列またはフィーチャ配列が失敗します。私は私の機能をループしている行PHPで複数の結合テーブルをループする
if ($prop_id != $row["prop_id"]) {
$feat = array(
"feature_name" => $row["feature_name"]
);
$prop_id = $row["prop_id"];
$features[] = $feat;
$projects[$counter]["rooms"]["feats"] = $features;
}
私はこの望ましくない出力を得る、そこにこのコードの塊を投げるとき
:だから私は、これを出力
if (isset($_POST['getAll'])) {
$sortBy = $_POST['getAll'];
$sqlQuery = "
SELECT
u.user_id,
u.user_username,
pr.project_id,
pr.created_date,
pr.closing_date,
pr.prize,
pr.project_desc,
pr.project_title,
pr.state,
prr.room_id,
prr.room_name,
prr.room_type,
prp.prop_id,
prp.comment_extra_details,
prp.feature_name,
prf.caption,
prf.filename,
prf.filetype,
prf.file_id,
prf.public_name
FROM users AS u
INNER JOIN projects as pr ON u.user_id = pr.creator_id
INNER JOIN project_rooms as prr ON prr.project_id = pr.project_id
INNER JOIN project_properties as prp ON prp.room_id = prr.room_id
INNER JOIN project_files as prf ON prf.room_id = prp.room_id
WHERE
state = 1
ORDER BY
`created_date` DESC";
}
$result = $conn->query($sqlQuery);
$proj_id = 0;
$room_id = 0;
$prop_id = 0;
$file_id = 0;
$projects = array();
$rooms = array();
$features = array();
$images = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
if ($proj_id != $row["project_id"]) {
$details = array(
"user_id" => $row["user_id"],
"username" => $row["user_username"],
"project_id" => $row["project_id"],
"created_date" => $row["created_date"],
"closing_date" => $row["closing_date"],
"prize" => $row["prize"],
"project_desc" => $row["project_desc"],
"project_title" => $row["project_title"],
"rooms" => array()
);
$proj_id = $row["project_id"];
$projects[] = $details;
$info = array();
}
if ($room_id != $row["room_id"]) {
$info = array(
"room_id" => $row["room_id"],
"room_name" => $row["room_name"],
"room_type" => $row["room_type"],
"comment_extra_details" => $row["comment_extra_details"],
"caption" => $row["caption"],
"feats" => array(),
"images" => array()
);
$room_id = $row["room_id"];
$rooms[] = $info;
$feat = array();
$counter = sizeof($projects) - 1;
$projects[$counter]["rooms"] = $info;
}
//This is giving me the trouble
//if ($prop_id != $row["prop_id"]) {
// $feat = array(
// "feature_name" => $row["feature_name"]
//);
//$prop_id = $row["prop_id"];
//$features[] = $feat;
//$projects[$counter]["rooms"]["feats"] = $features;
//}
else if ($file_id != $row["file_id"]) {
$img[] = array(
"filename" => $row["filename"],
"filetype" => $row["filetype"],
"file_id" => $row["file_id"],
"public_name" => $row["public_name"]
);
$file_id = $row["file_id"];
$images = $img;
$projects[$counter]["rooms"]["images"] = $images;
}
}
を持っていますこれは論理的な流れとループの終了によるものと思われます。
は、今私は5がある、間違いない15の機能があることを知っている、と3個のイメージが、私は何とか破壊機能や画像のない、どちらか一方を隔離するように見えることはできません。
EDIT - クエリが返すテーブルデータを視覚化しました。これが役立ちます。私はまだコメントできませんので
+---------+---------------+------------+---------------------+---------------------+-------+------------------+-------------------+------------+---------+-----------+-------------+---------+-----------------------+--------------+---------+-----------------------------------------------+------------+---------+-------------+
| user_id | user_username | project_id | created_date | closing_date | prize | project_desc | project_title | state | room_id | room_name | room_type | prop_id | comment_extra_details | feature_name | caption | filename | filetype | file_id | public_name |
+---------+---------------+------------+---------------------+---------------------+-------+------------------+-------------------+------------+---------+-----------+-------------+---------+-----------------------+--------------+---------+-----------------------------------------------+------------+---------+-------------+
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 42 | NULL | Decor | | b59b3bb7cac73e8cbba0f68795aba254_1459993038.p | image/png | 38 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 43 | NULL | Furniture | | b59b3bb7cac73e8cbba0f68795aba254_1459993038.p | image/png | 38 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 44 | NULL | Paint | | b59b3bb7cac73e8cbba0f68795aba254_1459993038.p | image/png | 38 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 45 | NULL | Flooring | | b59b3bb7cac73e8cbba0f68795aba254_1459993038.p | image/png | 38 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 46 | NULL | Apolstery | | b59b3bb7cac73e8cbba0f68795aba254_1459993038.p | image/png | 38 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 42 | NULL | Decor | | 21c3b842752b3866a37912048e6d0bbd_1459993053.j | image/jpeg | 39 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 43 | NULL | Furniture | | 21c3b842752b3866a37912048e6d0bbd_1459993053.j | image/jpeg | 39 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 44 | NULL | Paint | | 21c3b842752b3866a37912048e6d0bbd_1459993053.j | image/jpeg | 39 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 45 | NULL | Flooring | | 21c3b842752b3866a37912048e6d0bbd_1459993053.j | image/jpeg | 39 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 46 | NULL | Apolstery | | 21c3b842752b3866a37912048e6d0bbd_1459993053.j | image/jpeg | 39 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 42 | NULL | Decor | | 5b4645c9ee88704eae9a12e422d86ba2_1459993063.j | image/jpeg | 40 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 43 | NULL | Furniture | | 5b4645c9ee88704eae9a12e422d86ba2_1459993063.j | image/jpeg | 40 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 44 | NULL | Paint | | 5b4645c9ee88704eae9a12e422d86ba2_1459993063.j | image/jpeg | 40 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 45 | NULL | Flooring | | 5b4645c9ee88704eae9a12e422d86ba2_1459993063.j | image/jpeg | 40 | NULL |
| 10 | CalebB | 27 | 2016-04-06 21:38:00 | 2016-04-27 21:38:00 | 5500 | heres some janks | Just another test | qualifying | 26 | NULL | Family Room | 46 | NULL | Apolstery | | 5b4645c9ee88704eae9a12e422d86ba2_1459993063.j | image/jpeg | 40 | NULL |
+---------+---------------+------------+---------------------+---------------------+-------+------------------+-------------------+------------+---------+-----------+-------------+---------+-----------------------+--------------+---------+-----------------------------------------------+------------+---------+-------------+
ここに任意のヘルプまたは右方向へのポイントは非常に
PRF ON prf.room_id = prp.room_idは申し訳ありませんが、私は答えた – user3802077