Jump to content

Got data from database but doesn't show


eLIX

Recommended Posts

Hi,

 

I have a problem here.

I get data from a database and I need to put in a table.

 

the table dynamically adds rows depending on the results from the database.

 

So my rows are getting created but their's nothing in their.

 

What can be the problem here?

 

<table id="enquetesTable" cellspacing="0">
		<tr>
			<td class="columnTitleLeft">Naam</td>
			<td class="columnTitle">Aantal Vragen</td>
		</tr>
		<!-- BEGIN row -->
		<tr>
			<td class="leftColumn"><a href="#">{NAAM}</a></td>
			<td>{AANTALVRAGEN}</td>
		</tr>
		<!-- END row -->
	</table>

 

<?php

function getContent() {
require_once('MDB2.php');

// Template directory instellen
$tpl_main = new HTML_Template_IT('.');
$tpl_main->loadTemplatefile ('templates/overzicht.tpl', false, false);
$tpl_main->setCurrentBlock("row");

// Connectie instellen
$dsn = "mysql://usr_enquete:enquete@localhost/enquete";
$mdb2 =&   MDB2::connect($dsn, TRUE);
if (PEAR::isError($mdb2)) {
	die($mdb2->getMessage());
}

// SQL
$res =& $mdb2->query('SELECT * FROM enquetes');
// Altijd kijken of er geen errors zijn
if (PEAR::isError($res)) {
	die($res->getMessage());
} else {

	// Haal alle data op tot er geen rijen meer over zijn
	while (($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))) {
		$tpl_main->setVariable("NAAM", $row['Naam']);
		$tpl_main->setVariable("AANTALVRAGEN", $row['AantalVragen']);
		$tpl_main->parseCurrentBlock();
	}
}

$mdb2->disconnect();
return $tpl_main->get();
}

?>

Link to comment
https://forums.phpfreaks.com/topic/61118-got-data-from-database-but-doesnt-show/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.