diff options
author | chai <chaifix@163.com> | 2022-03-17 23:49:04 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-03-17 23:49:04 +0800 |
commit | cecb6f1a2e6e7f43601ec4aeac481817f9979422 (patch) | |
tree | 02a2fa2452f0f692aa26117a30f1d5b8028cb922 | |
parent | 90483f6eb389f041e0dbd0fca8bb766edbc85910 (diff) |
* paginate
-rw-r--r-- | booth.php | 4 | ||||
-rw-r--r-- | index.php | 27 | ||||
-rw-r--r-- | music.php | 38 | ||||
-rw-r--r-- | paginate.php | 23 | ||||
-rw-r--r-- | res/main.js | 12 | ||||
-rw-r--r-- | res/styles.css | 29 | ||||
-rw-r--r-- | search.php | 62 | ||||
-rw-r--r-- | tags.php | 3 | ||||
-rw-r--r-- | template.php | 9 |
9 files changed, 166 insertions, 41 deletions
@@ -19,7 +19,9 @@ window.onload = function() { <body> <div id="container"> - + <?php include_once('header.php');?> + <?php include_once('titlebar.php');?> + <div id="music_player_container"> <?php @@ -8,14 +8,27 @@ <body> <div id="container"> - <?php include_once('header.php');?> - <?php include_once('titlebar.php');?> - <?php include_once('music.php');?> - <?php - $musiclist = fetch_range_music(); - ?> - <?php include('musiclist.php');?> + <div id="container"> + <?php include_once('header.php');?> + <?php include_once('titlebar.php');?> + <?php include_once('music.php');?> + <?php include_once('config.php');?> + <?php + $current_page_index = $_GET['page']; + if($current_page_index == null){ + $current_page_index = 0; + } + $url = "./index.php?"; + $total_page = ceil(get_all_music_count() / Config::$music_per_page); + $musiclist = fetch_range_music($current_page_index * Config::$music_per_page, Config::$music_per_page); + ?> + <?php include('musiclist.php');?> + </div> + + <?php include 'paginate.php' ?> + </div> + </body> </html>
\ No newline at end of file @@ -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 @@ +<div id="paginate"> + +<?php +// external variables: +// echo $current_page_index ; +// echo $total_page ; +// echo $url; + + + for ($p=0; $p<$total_page; $p++) { + if($p == $current_page_index){ + html_paginate_link_current($url, $p); + } + else { + html_paginate_link($url, $p); + } + } + +?> + +</div> + +<div style="clear:both;"></div> 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 @@ -8,35 +8,45 @@ <body> <div id="container"> - <?php include_once('music.php');?> - <?php include_once('header.php');?> - <?php include_once('titlebar.php');?> - <?php include_once 'config.php'?> - <?php - $type = $_GET['type']; // 'tag', 'name' - $value = $_GET['value']; // tag id, name - $page = $_GET['page']; // page从0开始 - ?> - <div id="search-condition"> - <?php - $musiclist = null; - if($type == "tag") { - echo '<label class="search-hint">Tag : </label>'; - $tag = fetch_tag_by_id($value); - echo '<label class="search-value">' . $tag->name . "</label>"; - $musiclist = fetch_musics_by_tag($tag->uid, $page * Config::$music_per_page, Config::$music_per_page); - } - else if($type == "name") { - echo '<label class="search-hint">Searching : </label>'; - echo '<label class="search-value">' . $value . "</label>"; + <div id="container"> + <?php include_once('music.php');?> + <?php include_once('header.php');?> + <?php include_once('titlebar.php');?> + <?php include_once 'config.php'?> + <?php include_once 'functions.php'?> + <?php + $type = $_GET['type']; // 'tag', 'name' + $value = $_GET['value']; // tag id, name + $current_page_index = $_GET['page']; // page从0开始 + ?> + <div id="search-condition"> + <?php + $musiclist = null; + if($type == "tag") { + echo '<label class="search-hint">Tag : </label>'; + $tag = fetch_tag_by_id($value); + echo '<label class="search-value">' . $tag->name . "</label>"; + $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 '<label class="search-hint">Searching : </label>'; + echo '<label class="search-value">' . $value . "</label>"; - $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); + } - ?> + ?> + </div> + <?php include_once('musiclist.php');?> + </div> - <?php include_once('musiclist.php');?> - + + <?php include 'paginate.php' ?> + </div> </body> @@ -8,6 +8,9 @@ <body> <div id="container"> + <?php include_once('header.php');?> + <?php include_once('titlebar.php');?> + <div style="padding: 10px;"> <label>Tags:</label> <br/> <div class="tags_container"> 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 '<a href="' . $url . '&page=' . $pagei . '">' . ($pagei + 1) . '</a>'; +} + +function html_paginate_link_current($url, $pagei) { + echo '<a class="current" href="' . $url . '&page=' . $pagei . '">' . ($pagei + 1) . '</a>'; +} + + ?>
\ No newline at end of file |