3

I try to make board paging used beego.

So i did like this,

In controller

var articles []*models.Board
board.Data["startCount"] = startCount
board.Data["endCount"] = endCount

/* Template Test Query
num, err := o.QueryTable("board").Filter("Idx", 21).OrderBy("-idx").All(&articles)
*/

num, err := o.Raw("SELECT board.* FROM(SELECT @ROWNUM := @ROWNUM + 1 AS ROWNUM, board.* FROM board, (SELECT @ROWNUM := 0) R) board WHERE board.ROWNUM > ?;", 0).QueryRows(&articles)
if num == 0 || err == orm.ErrNoRows {
    board.Data["user_error"] = err
}
if err != orm.ErrNoRows && num > 0 {
    board.Data["nums"] = num
    board.Data["articles"] = articles
}

In veiw file

<tbody>
    {{ if not .articles }}
    <tr>
      <td colspan="5">No articles.</td>
    </tr>
    {{ else }}
    {{ $uri := .article_uri}}
    {{range $articles := .articles}}
    <tr>
      <td>{{$articles.Idx}}</td>
      <td><a href="{{urlfor "BoardController.Content" ":id" $articles.Idx}}">{{$articles.Title}}</a></td>
      <td>{{$articles.Nick}}</td>
      <td>{{date $articles.Date "y.m.d H:i"}}</td>
      <td>0</td>
    </tr>
    {{ end }}
    {{ end }}
</tbody>

When i used Template Test Query, i saw success print.

but i can see just empty table, since be changed to o.Raw( ... ).QueryRows(&articles)

Plz someone help me..

Current status

models

type Board struct{
Idx int64       `orm:"pk";form:"-"`
Id string       `form:"id"`
Title string    `form:"title"`
Body string     `form:"content"`
Nick string     `form:"nick"`
Date time.Time  `orm:"auto_now_add;type(datetime)"`
}

table

GeoLyu
  • 31
  • 2
  • Is your problem getting data out of the database, or adding it to the template? – Kiril Dec 23 '15 at 08:58
  • I'm having this issue right now: data is being retrieved from DB but the struct is filled with zeroes and empty strings. – Juanpa Aug 22 '21 at 23:30

0 Answers0