以不同的间隔选择多行
是否可以在 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';
}
Is it possible to select one row in MySQL and then miss 4 rows and then miss 3 rows and then miss 5 rows and then loop this until the end of the table?
I have found some LIMIT and OFFSET tutorials online, they work but, are only good for one off set. I need multiple.
I currently have this setup to work in PHP but I feel my PHP code is bloated because I only know a basic way of achieving this.
My PHP code is as follows
$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++;
}
What I am trying to do is select only Major triad notes from the Major scale.
I need to be able to select a base note from a table and then select at 3 different intervals to create chords.
Update
$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';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须将其应用到您的确切表格中,但它应该工作得很好。
% 12 给出一个完整的跳过周期,-4 和 -7(和 -0)是每个周期内的内部偏移量。
You have to apply this to your exact tables but it should work pretty good.
% 12 gives one complete cycle of skips, the -4 and -7 (and -0) is the internal offset within each cycle.
试试这个......我自己没有尝试过,但在我看来它应该有效:)
Try this...I haven't tried it myself but in my head it should work :)
我会考虑使用带有间隔(0,4,7,12,16,19等)的chord_note表,并将其用作SELECT的一部分,添加初始note_id值(27)+在chord_note中的条目表
变得更奇特,您甚至可以扩展chord_note表来保存不同音阶的不同间隔细节,只需修改子选择
I'd consider possibly using a chord_note table with the intervals (0,4,7,12,16,19, etc) and using that as part of your SELECT, adding the initial note_id value (27) + the entry in the chord_note table
Getting more fanciful, you could even extend the chord_note table to hold different inteval details for different scales, just modifying the subselect