Implement bulletin board paging

Asked 1 years ago, Updated 1 years ago, 114 views

Implementing node.js + express + ejs template.

I implemented the bulletin board with a lot of help from the hash code.

I implemented it without an editor. (Because of that, I still implemented uploading images to the body.)

And I want to implement paging.

I'm using mariadb.

select * from board order by _id desc limit 0, 10;

I even understood that I could easily share and import posts using the same query limit.

And,

<ul>
            <li><a href="#">«</a></li>    
            <% for(var i=1;i<8;i++ ) { %>
            <li><a href="#"><%=i%></a></li>    
            <% } %>
            <li><a href="#">»</a></li>
</ul>

Like this, I want to try Google's paging technique. (...getting only the front part without the interval)

But I don't know how to implement the link in the href="#" part in the code above.

I ask for your help me.

Thank you.

node.js express paging

2022-09-21 19:22

1 Answers

In the code you posted, href="#" comes out three times. You mean the first and last href="#"?

I don't know about express, but I think I'll make a controller that includes the page number in url and processes the url.

<ul>
            <li><a href="/pages/<%= i-1 %>">«</a></li>    
            <% for(var i=1;i<8;i++ ) { %>
            <li><a href="#"><%=i%></a></li>    
            <% } %>
            <li><a href="/pages/<%= i+1 %>">»</a></li>
</ul>

And when it's the last page and the first page, we'll need a separate branch.


2022-09-21 19:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.