【发布时间】:2012-01-11 19:42:48
【问题描述】:
是否可以在 MySQL 中选择一行然后错过 4 行然后错过 3 行然后错过 5 行然后循环直到表的末尾?
我在网上找到了一些 LIMIT 和 OFFSET 教程,它们有效,但只适用于一个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,但我对吉他和弦一无所知。我认为你应该详细说明这部分。
-
您可以更改偏移量并再次发送查询
-
1.您可能应该更喜欢 array 或其他一些复合数据类型,而不是大量以索引为后缀的变量。例如,
array_push($notes, $row["note"])。 2. 您应该明确地订购该查询,而不是依赖引擎意外选择您想要的顺序,即使这恰好是“隐式确定性事故”。 -
我的数据库中有 88 个音符,与全尺寸钢琴差不多。如果我以 4、3、5 的间隔演奏每个音符,我将弹奏 C 和弦。我想选择所有这些音符,但将那些落在间隔上的音符标记为“开”,其余的标记为“关”。然后我可以为吉他生成和弦图。喜欢这个页面gtdb.org/tuning_links/chord_generator/chords.php