是否可以在MySQL中選擇一行,然後錯過4行,然後錯過3行然後錯過5行,然後循環直到表的結尾?以不同的時間間隔選擇多行
我已經在網上找到了一些LIMIT和OFFSET教程,但它們工作正常,但只適用於一套。我需要多個。
我目前有這個設置工作在PHP中,但我覺得我的PHP代碼臃腫,因爲我只知道實現這一點的基本方法。
我的PHP代碼如下
$int_count = 0;
$result = mysql_query("SELECT * FROM guitar_tunings_chords WHERE note_id >= '27'");
while ($row = mysql_fetch_array($result)) {
if ($int_count == 0)$n_1 = ($row["note"]);
if ($int_count == 4)$n_2 = ($row["note"]);
if ($int_count == 7)$n_3 = ($row["note"]);
if ($int_count == 12)$n_4 = ($row["note"]);
if ($int_count == 16)$n_5 = ($row["note"]);
if ($int_count == 19)$n_6 = ($row["note"]);
if ($int_count == 24)$n_7 = ($row["note"]);
if ($int_count == 28)$n_8 = ($row["note"]);
if ($int_count == 31)$n_9 = ($row["note"]);
if ($int_count == 36)$n_10 = ($row["note"]);
if ($int_count == 40)$n_11 = ($row["note"]);
if ($int_count == 43)$n_12 = ($row["note"]);
if ($int_count == 48)$n_13 = ($row["note"]);
if ($int_count == 52)$n_14 = ($row["note"]);
$int_count++;
}
我所試圖做的是從大尺度只選擇大三和絃音符。
我需要能夠從表中選擇一個基本音符,然後選擇3個不同的間隔來創建和絃。
更新
$result2 = mysql_query("SELECT *
FROM `guitar_tunings_links`
JOIN guitar_tunings_chords ON guitar_tunings_links.".$funtion_string." = guitar_tunings_chords.note
WHERE tuning = '".$chrd_tn."'") or die(mysql_error());
while ($row = mysql_fetch_array($result2)) {
$bridge_note = ($row["note_id"]);
}/*
var_dump ($key_note);
var_dump ($bridge_note);
var_dump ($funtion_string);
var_dump ($chrd_tn);*/
// SELECT * FROM `guitar_tunings_chords` WHERE `note_id` >= 28 LIMIT 0,8
$result4 = mysql_query("SELECT * FROM `guitar_tunings_chords` WHERE `note_id` >= ".$bridge_note." LIMIT ".$tuning_capo.",8") or die(mysql_error());
while ($row = mysql_fetch_array($result4)) {
//Notes
$note = ($row["note"]);
// Replace # with z
$note = str_replace("#", "z", $note);
// Distinguish nut notes on or off
if (preg_match("/\b".$note."\b/i", $notes_array)) {
$n_nut_style = 'note_nut_on';
} else { $n_nut_style = 'note_nut_off';
}
// Distinguish fretboard notes on or off
if (preg_match("/\b".$note."\b/i", $notes_array)) {
$n_style = 'note_on';
} else { $n_style = 'note_off';
}
我知道PHP,但我不知道吉他和絃。我認爲你應該詳細說明這一部分。 – Hubro 2012-01-11 19:49:25
您可以更改偏移量並再次發送查詢 – 2012-01-11 19:51:03
1.您應該更喜歡一個*數組*或其他一些複合數據類型,而不是索引後綴變量。例如''array_push($ notes,$ row [「note」])''。 2.您應明確訂購該查詢,而不是依賴引擎無意中挑選您想要的訂單,即使這恰好是「隱含確定性事故」。 – pilcrow 2012-01-11 20:42:04