Forums | Mahara Community

Developers /
Displaying Data from the Database

15 October 2016, 12:57 AM


A simple question : how can I display data with Mahara ?

I found some functions in the file dml.php but how the interaction between a php file and smarty works ?
SELECT *, foreach ...

For example, I want to create a page that displays a new page of a user, so nothing to do with the portfolio page.

Documentation exists ?

Thank you !

15 October 2016, 3:19 AM

My solution :

I use the function get_records_sql_array() and I return an array in php.

So with smarty I used :


{foreach from=$myArray item=myelement}
    {$myelement} <br/>



Ghada El-Zoghbi's profile picture
Posts: 121

24 October 2016, 5:56 PM

Hi De Chiara,

Do you still require help with this? It looks like you might have figured it out yourself...




16 March 2017, 11:50 PM



I'm sorry ! I had not read your answer !! yell

Uhm yes for the arrays is good.


But I have some questions !

The basics for coding with Mahara !


How can I write for example :

function test() 
    global $db;
    $id = (int)$_GET["id"];
    $test = $db->prepare("SELECT * FROM tests WHERE id = ?");
    $test = $test->fetch();
        header("Location: index.php");
        return $test;

$test = test();

<?= $test["title"]; ?>

And :

try { $bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', ''); }

catch(Exception $e) { die('Error : '.$e->getMessage()); }

$req = $bdd->prepare('INSERT INTO posttest (title, description) VALUES(?, ?)');

$req->execute(array($_POST['title'], $_POST['description']));

The sql functions for a crud for example ..

I imagine that in Mahara there are functions that automatically perform these operations.

Thanks !! laughing

24 March 2017, 4:38 AM

Ok I find.

I use the functions get_records_sql_array(), get_field_sql(), insert_record() and execute_sql().

In any case it's a share that there isn't a documentation or help for these basic things.

It is demotivating.

Kristina Hoeppner's profile picture
Posts: 3443

24 March 2017, 9:43 AM

Hello Antonella,

Thank you for sharing the functions you use. Our developer documentation is lacking in some aspects, but everyone can help make it better. Your account allows you to log in to the wiki with the same credentials. You could add your insight to the documentation.

Thank you



6 results