Page 1 of 1

Learning building modules

Posted: Thu Sep 05, 2019 2:45 pm
by musicscore
Hi all,

I'm building a module (FAQ's) but have a problem.

This is my code of the default.php :

Code: Select all

<?php

if( !defined('CMS_VERSION') ) exit;

$query = new CategoryQuery;
$categorys = $query->GetMatches();

$sql = 'SELECT * FROM '.CMS_DB_PREFIX.'mod_msfaq_questions WHERE category = "Category 1"';
$questionrow = $db->GetArray($sql);

print_r($questionrow);

$out = NULL;
foreach( $questionrow as $row ) {
		$out[$row['question']] = trim($row['question']);
	}


$tpl = $smarty->CreateTemplate($this->GetTemplateResource('default.tpl'),null,null,$smarty);
$tpl->assign('categorys',$categorys);
$tpl->assign('questions',$out);
$tpl->display();

?>
Now this is my default.tpl template :

Code: Select all

<div class="msfaq_wrapper">
test
	{foreach $categorys as $category}
		<div class="category">
			<div class="row">
				<div class="categoryline"><a href="{cms_action_url action='categoryquestions' cid=$category->id}">{$category->category_name}</a>
				</div>
			</div>
		</div> 

	{foreachelse}     
	<div class=”noquestions”>{$mod->Lang('noquestion')}</div>
	{/foreach}
	
	{foreach $questions as $question}
		<div class="questions">
			<div class="row">
				<div class="questionline">{$question->question} {$question->answer}
				</div>
			</div>
		</div>
	{/foreach}
</div>
The output of the print_r($questionrow) is :

Code: Select all

Array ( [0] => Array ( [id] => 11 [category] => Category 1 [question] => Vraag 1 [answer] =>

Datum test
[creation_date] => 0 [modified_date] => 0 ) [1] => Array ( [id] => 12 [category] => Category 1 [question] => Vraag 2 [answer] =>

Datum Test 2
[creation_date] => 2019 [modified_date] => 0 ) [2] => Array ( [id] => 13 [category] => Category 1 [question] => Vraag 5 [answer] =>

Test 5 dsatum
[creation_date] => 1567202400 [modified_date] => 0 ) )
test 
So the query is oke (I think)

Please help. Why is there no output on the screen showing the questions ?
The categories are showing oke.

Please help. I want to learn make cmsms modules.

[Solved] Learning building modules

Posted: Tue Sep 10, 2019 5:51 pm
by musicscore
The problem was caused by the read of the array.