Learning building modules

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
musicscore
Power Poster
Power Poster
Posts: 444
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Learning building modules

Post 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.
musicscore
Power Poster
Power Poster
Posts: 444
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

[Solved] Learning building modules

Post by musicscore »

The problem was caused by the read of the array.
Post Reply

Return to “Developers Discussion”