In this code, I have a function in which I find the users' names. It finds them and prints all the names inside the loop but when I return the s variable outside the loop, it prints only the first name. It does not print all the names.
Although I append s variable in another variable also but still does not work.
type Signup struct {
Names string
Emails string
}
func FindNames() string {
db := Connect()
var s string
rows, err := db.Query("select names from Signup")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var signup Signup
err := rows.Scan(&signup.Names)
if err != nil {
log.Fatal(err)
}
// s = signup.Names
// fmt.Println(s)
s = fmt.Sprintf("%s", signup.Names)
}
return s
}