Answer the question
In order to leave comments, you need to log in
How to translate the result of type sql.Result into a string?
Get value from database:
maxvalue, err := db.Exec("SELECT MAX(points) FROM items")
cannot use maxvalue (type sql.Result) as type string in assignment
t.ExecuteTemplate(w, "single", Data)
Answer the question
In order to leave comments, you need to log in
You are not using that function. Exec is needed to execute a query that returns nothing.
You need Query
And it's better to put it all in a separate function in order to use defer
func GetMaxPoints(db *sql.DB) (int64, error) {
rows, err := db.Query(`SELECT MAX(points) FROM items`)
if err != nil {
return 0, err
}
defer rows.Close()
rows.Next()
var maxPoints int64
err = rows.Scan(&maxPoints)
return maxPoints, err
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question