MySQL 配列から別の MySQL テーブルに結果を取得しようとしていますが、特定の静的な順序です。
これは私の配列です(MySQL):
Array
(
[1] => Array
(
[id] => 19
[user_id] => 18
[size] => Large
)
[2] => Array
(
[id] => 18
[user_id] => 17
[size] => Large
)
[3] => Array
(
[id] => 11
[user_id] => 8
[size] => Large
)
[4] => Array
(
[id] => 7
[user_id] => 2
[size] => Large
)
[5] => Array
(
[id] => 3
[user_id] => 1
[size] => Large
)
[6] => Array
(
[id] => 16
[user_id] => 16
[size] => Small
)
[7] => Array
(
[id] => 15
[user_id] => 15
[size] => Small
)
[8] => Array
(
[id] => 14
[user_id] => 14
[size] => Small
)
[9] => Array
(
[id] => 10
[user_id] => 4
[size] => Small
)
[10] => Array
(
[id] => 8
[user_id] => 3
[size] => Small
)
[11] => Array
(
[id] => 4
[user_id] => 1
[size] => Small
)
[12] => Array
(
[id] => 17
[user_id] => 16
[size] => Wide
)
[13] => Array
(
[id] => 12
[user_id] => 12
[size] => Wide
)
[14] => Array
(
[id] => 13
[user_id] => 13
[size] => Tall
)
[15] => Array
(
[id] => 5
[user_id] => 1
[size] => Tall
)
)
この配列出力を使用して、特定の順序でデータを別のテーブルに強制しようとしています。
ここに私が持っているものがあります:
$mysql_array = $mySQLi->DoSelect("
(SELECT id, user_id, size FROM `table1` WHERE size = 'Large' GROUP BY user_id ORDER BY id DESC LIMIT 0,5)
UNION ALL
(SELECT id, user_id, size FROM `table1` WHERE size = 'Small' GROUP BY user_id ORDER BY id DESC LIMIT 0,6)
UNION ALL
(SELECT id, user_id, size FROM `table1` WHERE size = 'Wide' GROUP BY user_id DESC ORDER BY id DESC LIMIT 0,2)
UNION ALL
(SELECT id, user_id, size FROM `table1` WHERE size = 'Tall' GROUP BY user_id DESC ORDER BY id DESC LIMIT 0,4)
");
for($i = 1; $streamItems[$i] = $mySQLi->GetArray($mysql_array); $i++)
{
// Large images
if($i === 1 && $streamItems[$i]['size'] == 'Large') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 1); }
if($i === 2 && $streamItems[$i]['size'] == 'Large') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 4); }
if($i === 3 && $streamItems[$i]['size'] == 'Large') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 10); }
if($i === 4 && $streamItems[$i]['size'] == 'Large') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 11); }
if($i === 5 && $streamItems[$i]['size'] == 'Large') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 12); }
// Small
if($i === 6 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 2); }
if($i === 7 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 3); }
if($i === 8 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 6); }
if($i === 9 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 7); }
if($i === 10 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 13); }
if($i === 11 && $streamItems[$i]['size'] == 'Small') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 14); }
// Wide
if($i === 12 && $streamItems[$i]['size'] == 'Wide') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 5); }
if($i === 13 && $streamItems[$i]['size'] == 'Wide') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 17); }
// Tall
if($i === 14 && $streamItems[$i]['size'] == 'Tall') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 8); }
if($i === 15 && $streamItems[$i]['size'] == 'Tall') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 9); }
if($i === 16 && $streamItems[$i]['size'] == 'Tall') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 15); }
if($i === 17 && $streamItems[$i]['size'] == 'Tall') { saveToNewTable(1, $streamItems[$i]['id'], $streamItems[$i]['user_id'], 16); }
}
function saveToNewTable($stream_id, $artwork_id, $user_id, $sequence)
{
global $mySQLi;
$mySQLi->DoSql("
INSERT INTO
table2
(
stream_id,
artwork_id,
user_id,
sequence
)
VALUES
(
".$stream_id.",
".$artwork_id.",
".$user_id.",
".$sequence."
)
");
}
何が起こるかというと、$mysql_array からの最初の結果のみが新しいテーブルに挿入されますが、3 回です。なんで3回?
次の警告も表示されます。
乾杯