是否可以在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