From cecb6f1a2e6e7f43601ec4aeac481817f9979422 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 17 Mar 2022 23:49:04 +0800 Subject: * paginate --- booth.php | 4 +++- index.php | 27 ++++++++++++++++++------- music.php | 38 ++++++++++++++++++++++++++++++++++- paginate.php | 23 ++++++++++++++++++++++ res/main.js | 12 ++++++------ res/styles.css | 29 +++++++++++++++++++++++++++ search.php | 62 ++++++++++++++++++++++++++++++++++------------------------ tags.php | 3 +++ template.php | 9 +++++++++ 9 files changed, 166 insertions(+), 41 deletions(-) create mode 100644 paginate.php diff --git a/booth.php b/booth.php index 8e62fdd..8f1b675 100644 --- a/booth.php +++ b/booth.php @@ -19,7 +19,9 @@ window.onload = function() {
- + + +
- - - - - +
+ + + + + + +
+ + +
+ \ No newline at end of file diff --git a/music.php b/music.php index acd4165..797f48a 100644 --- a/music.php +++ b/music.php @@ -207,8 +207,20 @@ function fetch_musics_by_name($name, $from=0, $count=100) { return $arr; } +function get_music_count_by_name($name) { + $sql = "SELECT COUNT(*) as count FROM " . Config::$tb_music . " WHERE title LIKE '%" . $name . "%'"; + $result = execute_sql($sql); + if($result == null || $result->num_rows == 0) + return 0; + $row = mysqli_fetch_assoc($result); + if($row != null){ + return $row['count']; + } + return 0; +} + function fetch_musics_by_tag($tag_id, $from=0, $count=100) { - $sql = "SELECT music_id FROM " . Config::$tb_music_tag . " WHERE tag_id=" . $tag_id ;//. " ORDER BY time DESC LIMIT " . $from . ", " . $count; + $sql = "SELECT music_id FROM " . Config::$tb_music_tag . " WHERE tag_id=" . $tag_id . " ORDER BY music_id DESC LIMIT " . $from . ", " . $count; $result = execute_sql($sql); if($result == null || $result->num_rows == 0) return ; @@ -221,6 +233,18 @@ function fetch_musics_by_tag($tag_id, $from=0, $count=100) { return $arr; } +function get_music_count_by_tag($tag_id) { + $sql = "SELECT COUNT(*) as count FROM " . Config::$tb_music_tag . " WHERE tag_id=" . $tag_id ; + $result = execute_sql($sql); + if($result == null || $result->num_rows == 0) + return 0; + $row = mysqli_fetch_assoc($result); + if($row != null){ + return $row['count']; + } + return 0; +} + function fetch_musics_by_album($album_id, $from=0, $count=100) { $sql = "SELECT music_id FROM " . Config::$tb_album_music . " WHERE album_id=" . $album_id . " ORDER BY time DESC LIMIT " . $from . ", " . $count; $result = execute_sql($sql); @@ -235,6 +259,18 @@ function fetch_musics_by_album($album_id, $from=0, $count=100) { return $arr; } +function get_all_music_count() { + $sql = "SELECT COUNT(*) as count FROM " . Config::$tb_music; + $result = execute_sql($sql); + if($result == null || $result->num_rows == 0) + return 0; + $row = mysqli_fetch_assoc($result); + if($row != null){ + return $row['count']; + } + return 0; +} + function add_unique_music_tag( $music_id, $tag_id ) { $result = execute_sql("SELECT * FROM " . Config::$tb_music_tag . " where music_id=" . $music_id . " and tag_id=" . $tag_id ); diff --git a/paginate.php b/paginate.php new file mode 100644 index 0000000..c6ce295 --- /dev/null +++ b/paginate.php @@ -0,0 +1,23 @@ +
+ + + +
+ +
diff --git a/res/main.js b/res/main.js index 543cd16..2f42d19 100644 --- a/res/main.js +++ b/res/main.js @@ -75,13 +75,13 @@ function changeMusicListWidth () { music_list.style.width = Math.floor( outer_width / 120) * 120; } -window.onload = function() { - changeMusicListWidth(); -} +// window.onload = function() { +// changeMusicListWidth(); +// } -window.onresize = function(){ - changeMusicListWidth(); -} +// window.onresize = function(){ +// changeMusicListWidth(); +// } // time diff --git a/res/styles.css b/res/styles.css index 92fdd2d..e7e8c08 100644 --- a/res/styles.css +++ b/res/styles.css @@ -151,6 +151,7 @@ body{ #music_player_container { max-width: 95%; margin: 0 auto; + margin-top: 10px; } #music_player_container .music_cover{ @@ -195,4 +196,32 @@ body{ font-weight:bold; } +#paginate { + width: 100%; +} + +#paginate a { + color:rgb(0, 0, 0); + text-decoration-line: none; + display: block; + width: 30px; + height: 30px; + text-align: center; + line-height: 30px; + float:left; + margin-right: 5px; +} + +#paginate a:hover{ + color:#fff; + background-color: #000; + text-decoration-line: none; + display: block; +} +#paginate .current{ + color:#fff; + background-color: #000; + text-decoration-line: none; + display: block; +} \ No newline at end of file diff --git a/search.php b/search.php index 4a838e4..472c508 100644 --- a/search.php +++ b/search.php @@ -8,35 +8,45 @@
- - - - - -
- Tag : '; - $tag = fetch_tag_by_id($value); - echo '"; - $musiclist = fetch_musics_by_tag($tag->uid, $page * Config::$music_per_page, Config::$music_per_page); - } - else if($type == "name") { - echo ''; - echo '"; +
+ + + + + + +
+ Tag : '; + $tag = fetch_tag_by_id($value); + echo '"; + $musiclist = fetch_musics_by_tag($tag->uid, $current_page_index * Config::$music_per_page, Config::$music_per_page); + $url = "./search.php?type=tag&value=" . $value; + $total_page = ceil(get_music_count_by_tag($tag->uid) / Config::$music_per_page); + } + else if($type == "name") { + echo ''; + echo '"; - $musiclist = fetch_musics_by_name($value, $page * Config::$music_per_page, Config::$music_per_page); - } + $musiclist = fetch_musics_by_name($value, $current_page_index * Config::$music_per_page, Config::$music_per_page); + $url = "./search.php?type=name&value=" . $value; + $total_page = ceil(get_music_count_by_name($value) / Config::$music_per_page); + } - ?> + ?> +
+ +
- - + + +
diff --git a/tags.php b/tags.php index d1c4282..bd35566 100644 --- a/tags.php +++ b/tags.php @@ -8,6 +8,9 @@
+ + +

diff --git a/template.php b/template.php index 04965b6..49d96ee 100644 --- a/template.php +++ b/template.php @@ -55,4 +55,13 @@ function html_music_player($music) { } +function html_paginate_link($url, $pagei) { + echo '' . ($pagei + 1) . ''; +} + +function html_paginate_link_current($url, $pagei) { + echo '' . ($pagei + 1) . ''; +} + + ?> \ No newline at end of file -- cgit v1.1-26-g67d0