Populate record in select with group


Out put will be like this. and the record from database.

Is this a <select> in HTML? Do you build the HTML using Go templates? How is your question related to Go?

Yes that is . I want to put the record from database in a group

How do you use Go for this?

This is the code. How can i display in template

 func Fill(res http.ResponseWriter, req *http.Request) {
userName:= getUserName(req)
if userName != "" {
	UserEmail := userName

	car :=car{}
	records :=[]car{}

	selDB, err :=config.DB.Query("SELECT Car FROM tblcars")
	if err != nil {
	for selDB.Next() {
		var car string
		err = selDB.Scan(&car)
		if err != nil {
		car.car = car
 		records = append(records, car)				
			Title:  "Dashboard",
			UserEmail: UserEmail,
			car: records,
		templating.Display(res, "index",data)
} else {
	http.Redirect(res, req, "/", 302)


	  <optgroup label="Swedish Cars">
		<option value="volvo">Volvo</option>
		<option value="saab">Saab</option>
	  <optgroup label="German Cars">
		<option value="mercedes">Mercedes</option>
		<option value="audi">Audi</option>

Which library is templating?


How to do it in json

can i do it this way. How can i make like this from database?

	  "name": "Swedish Cars",
	  "car": {
		"Nameofcar" : "Volvo",
		"Nameofcar" : "Saab"
	  "name": "German Cars",
	  "car": {
		"Nameofcar" : "Mercedes",
		"Nameofcar" : "Audi"

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.