Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2021-02-05 10:15:19
- ugur
- New Member
- Registered: 2021-02-05
- Posts: 4
textpattern php database query
Hi
I want to list data from a database table and show it on the page
MY SAMPLE PHP CODE
$qry = $connect->query("SELECT * FROM users");
while ($result = $qry->fetch_assoc()) {
echo '<h1>' . $result['name'] . '</h1>';
}
please help me thanks
Last edited by ugur (2021-02-05 11:30:21)
Offline
Re: textpattern php database query
Hi Ugur and welcome to txp
Is your site powered by Textpattern?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2021-02-05 10:41:03
- ugur
- New Member
- Registered: 2021-02-05
- Posts: 4
Re: textpattern php database query
Yes
I installed textpattern
very great cms
but I can’t do database operations
Offline
Re: textpattern php database query
Hi ugur and welcome,
Textpattern provides a series of tags that you can use to retrieve information from the database without having to dive into PHP*. For example, for you use case of a list of registered users, you can use txp:authors.
This is an example from that page that, for example, lists all users who are “publishers” or “managing editors” with a link to their author page (e.g. the page that might list the articles they have written) along with their e-mail address.
<txp:authors group="publisher, managing_editor" wraptag="ul" break="li">
<txp:author link="1" />
(<txp:author_email />)
</txp:authors>
There are a wide range of tags for retrieving data stored in articles, links, images and so on as well as ways of categorising or grouping them: See the tag index for a quick overview and the Textpattern docs in general for more information.
*The tags pass this to Textpattern’s internal database handling functions that deal with establishing the DB connection and safely querying the DB. For the most part, you will rarely have to fashion your own queries, but there are plugins like smd_query and etc_query that enable you to create very specific queries.
TXP Builders – finely-crafted code, design and txp
Offline
#5 2021-02-05 11:39:46
- ugur
- New Member
- Registered: 2021-02-05
- Posts: 4
Re: textpattern php database query
thank you Jakob
I want to create new database tables and show them on the pages. Can I achieve this? Is there a way to use php or should I use the method you call?
Offline
Re: textpattern php database query
Textpattern comes with a set of core tables with predefined structures for common content types/uses and the in-built tags work with these tables. The article table (‘textpattern’ in the database) is designed to be relatively flexible so that it can serve many different purposes with 10 possible custom fields for own use.
If you want to create your own tables for a specific content type and then access them via a separate admin panel to edit them, then you’re getting into plugin territory. The core (all on GitHub) contains functions for DB queries, sanitising data, building admin panels with list views and edit panes but it’s definitely much more involved than inserting some queries.
If you have just a particular case you want to cater for, e.g. a table that already exists in another form (for example, I have a site with a list of suppliers exported from a database), you can query that database independently if it’s on the same server using a combination of the plugins rah_swap and smd_query. In my case the site is built with textpattern and the other database on the same server is queried to sort or filter the suppliers according to different criteria.
If your primary use will be for custom table types and you have little use for Textpattern’s pre-existing structure, it may not be the right choice for you. You might want to investigate using a PHP framework that provides you with the DB creation and retrieval functions independently, and then add an admin panel on the back of those content types for editing them (e.g. like with laravel etc. for which there are a number of admin back-ends).
TXP Builders – finely-crafted code, design and txp
Offline
Re: textpattern php database query
ugur wrote #328538:
Is there a way to use php …?
Certainly, just wrap it in <txp:php />
tag:
<txp:php>
echo 'Yes we can!';
</txp:php>
To query txp own DB, there is a number of handy safe_
functions that you can find in txplib_db.php
. At your own risk, as jakob says.
Offline
Pages: 1