在smarty循环中显示mysql查询

i want show query in smarty loop with some like title :

table1 (courses): id, title

table2 (questions): id, title, teachers_id

query:

$this->ctitle_qtitle = DatabaseHandler::GetAll("
                 SELECT courses.title , questions.title
                 FROM courses
                 JOIN questions
                 ON courses.id = questions.courses_id "); 

this query work true, and in .tpl file i use loop:

{section name=i loop=$obj->ctitle_qtitle}
    <tr>
        <td><h3><a href="#">{$obj->ctitle_qtitle[i].title</a></h3></td>
        <td>{$obj->ctitle_qtitle[i].title}</td>
        <td><a href="#" class="ico del">Delete</a>
         <a href="#" class="ico edit">Edit</a></td>
    </tr>
{/section}

how can i use courses.title or question.title in smarty result ?

You need to modify your SQL query from:

$this->ctitle_qtitle = DatabaseHandler::GetAll("
                 SELECT courses.title , questions.title
                 FROM courses
                 JOIN questions
                 ON courses.id = questions.courses_id "); 

to

$this->ctitle_qtitle = DatabaseHandler::GetAll("
                 SELECT courses.title AS `ctitle` , questions.title AS `qtitle`
                 FROM courses
                 JOIN questions
                 ON courses.id = questions.courses_id "); 

This way you create aliases for column names (earlier this was problem because 2 columns had the same name) and now you can simple use ctitle and qtitle in Smarty as for example:

{section name=i loop=$obj->ctitle_qtitle}
    <tr>
        <td><h3><a href="#">{$obj->ctitle_qtitle[i].ctitle</a></h3></td>
        <td>{$obj->ctitle_qtitle[i].qtitle}</td>
        <td><a href="#" class="ico del">Delete</a>
         <a href="#" class="ico edit">Edit</a></td>
    </tr>
{/section}