Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-17 22:36:47

lindabb
Member
Registered: 2023-02-17
Posts: 132

List of new table

Hello,
I have table called products, has id, name and price, (mysql)
I’m using latest textpattern, (v4.8.8)
I like to connect to mysql and list above table on one of the pages, with pagination ,
is that possible with textpattern ?

Thank you for any help

Offline

#2 2023-02-18 02:33:03

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Re: List of new table

I tried with smd_query and got it working, but this doesn’t have pagination:

<txp:smd_query query="SELECT id,name,price FROM products" wraptag="ul" break="li">
<strong><txp:smd_query_info type="field" item="name" />:</strong> <txp:smd_query_info type="field" item="price" />
</txp:smd_query>

Offline

#3 2023-02-18 12:13:20

etc
Developer
Registered: 2010-11-11
Posts: 5,236
Website GitHub

Re: List of new table

Pagination is not difficult, you just need to count pages. I do it with etc_query, but smd_query will surely work fine too. It is assumed below that products table in in the same db that txp, but this can be adapted.

<!-- count records paged by 10 and store the total in a variable -->
<txp:variable name="numpg" value='<txp:etc_query data="SELECT CEILING(COUNT(*)/10) FROM products" />' />

<!-- display a pagination bar driven by 'pgnum' URL parameter -->
<txp:pages total='<txp:variable name="numpg" />' pg="pgnum">
    <txp:pages shift wraptag="nav" break=" | "><txp:yield item="page" /></txp:pages>
</txp:pages>

<!-- calculate the offset -->
<txp:variable name="pgoffset" escape="integer">
    <txp:evaluate query='10*(<txp:page_url type="pgnum" default="1" /> - 1)' />
</txp:variable>

<!-- output data -->
<txp:etc_query data='SELECT id, name, price FROM products LIMIT <txp:variable name="pgoffset" />, 10 ORDER BY name' wraptag="ul" break="li">
    <strong>{name?}</strong>: {price?}
</txp:etc_query>

Offline

#4 2023-02-19 15:02:28

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: List of new table

Thank you both, after installed missing 2 plugins both worked very good

but etc’s solution worked for me better , I need pagination.

Thank you both for your help and support

Offline

Board footer

Powered by FluxBB