eg.GET("/", func(c *gin.Context) {
query := "SELECT id, r_id, p_id, s_id from whole ORDER BY id DESC limit 6"
r, err := db.Query(query)
if err != nil {
log.Fatalln("DB Connetion ERROR occured :", err)
}
data := []PRS_id{}
for r.Next() {
var temp PRS_id
r.Scan(&temp.ID, &temp.RID, &temp.PID, &temp.SID)
data = append(data, temp)
}
fmt.Println(data)
c.HTML(http.StatusOK, "index.html", data)
})
I’m making my own blog and there are three category : projects, review, study
I made each category’s table in my DB, and also made ‘whole’ DB which has foreign key with each categories to make viewing ‘recent 6 posts’
the number of posts are 9
In my thought, the ‘data’ structure has to print
{9,3,0,0}{8,0,3,0}{7,3,0,0}{6,0,0,3}{5,0,0,3}{4,0,3,0}
but it actually prints
{9,3,0,0}{8,0,0,0}{7,3,0,0}{6,0,0,0}{5,0,0,0}{4,0,0,0}
the id and PID printed well, but Idk why RID and SID didn’t print well
and when I write that query in DB at console, it works well.
anyone knows about this problem?