add and refine thunderball results page
This commit is contained in:
21
helpers/distinctresults.go
Normal file
21
helpers/distinctresults.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package helpers
|
||||
|
||||
import "database/sql"
|
||||
|
||||
func GetDistinctValues(db *sql.DB, column string) ([]string, error) {
|
||||
query := "SELECT DISTINCT " + column + " FROM results_thunderball ORDER BY " + column
|
||||
rows, err := db.Query(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var values []string
|
||||
for rows.Next() {
|
||||
var val string
|
||||
if err := rows.Scan(&val); err == nil {
|
||||
values = append(values, val)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
18
helpers/pagination.go
Normal file
18
helpers/pagination.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func GetTotalPages(db *sql.DB, tableName, whereClause string, args []interface{}, pageSize int) (totalPages, totalCount int) {
|
||||
query := "SELECT COUNT(*) FROM " + tableName + " " + whereClause
|
||||
row := db.QueryRow(query, args...)
|
||||
if err := row.Scan(&totalCount); err != nil {
|
||||
return 1, 0
|
||||
}
|
||||
totalPages = (totalCount + pageSize - 1) / pageSize
|
||||
if totalPages < 1 {
|
||||
totalPages = 1
|
||||
}
|
||||
return totalPages, totalCount
|
||||
}
|
||||
25
helpers/template.go
Normal file
25
helpers/template.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
)
|
||||
|
||||
func TemplateFuncs() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
"plus1": func(i int) int { return i + 1 },
|
||||
"minus1": func(i int) int {
|
||||
if i > 1 {
|
||||
return i - 1
|
||||
}
|
||||
return 0
|
||||
},
|
||||
"mul": func(a, b int) int { return a * b },
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"min": func(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user