Answer the question
In order to leave comments, you need to log in
How to get data from a table in a database in Modx Revolution?
Hello.
There is a site on modx revo. In phpMyAdmin, in the database that was created for the site, I added a table.
I need to get data from this table and display it in a snippet on the page according to the condition (for example, if the table column has a value of 1, then I display it). How to do it and what to use, in which direction to look?
PS I googled ways through xPDO, but in all examples they show how to get any data from resources or other things, which I can do myself in standard ways, but I didn’t find how to get it from database tables. Maybe I'm writing the query incorrectly, since my level of knowledge of the database and SQL is limited to SELECT * FROM TABLE
Answer the question
In order to leave comments, you need to log in
xPDO quite allows you to work with arbitrary tables from the database. Link for review.
Example:
$sql = "SELECT * FROM modx_users WHERE active = 1";
// Вариант 1.
$statement = $modx->query($sql);
$users = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($users as $user) {
print $user['username'] .'<br/>';
}
// Вариант 2. Если не нужно зачитывать данные в массив
foreach ($modx->query($sql) as $user) {
print $user['username'] .'<br/>';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question