# Forums | Mahara Community

## Developers / Displaying Data from the Database

Posts: 25

15 October 2016, 12:57 AM

Hello,

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 !
Posts: 25
##### Re: Displaying Data from the Database

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/>
{/foreach}

Posts: 122
##### Re: Displaying Data from the Database

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...

Thanks,

Posts: 25
##### Re: Displaying Data from the Database

16 March 2017, 11:50 PM

Hello,

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->execute([id]);    $test =$test->fetch();        if(empty($test)) header("Location: index.php"); else 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 !!

Posts: 25
##### Re: Displaying Data from the Database

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.

Posts: 3587
##### Re: Displaying Data from the Database

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 mahara.org account allows you to log in to the wiki with the same credentials. You could add your insight to the documentation.

Thank you

Kristina

6 results