PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 24th, 2007, 12:45 PM
eLIX eLIX is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 5 eLIX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 13 sec
Reputation Power: 0
Elements after template block keep returning

hi,

I want to dynamically create rows in a table for questions and answers. After that you can submit them.
Problem is my submit button also keeps returning after each question (with it's answers)

index.php:

PHP Code:
<?php

// Je moet de basisklasse includen zodat die gekend is in de file
require_once('html/IT.php');

// Het templateobject instantiėren
$tpl = new HTML_Template_IT('.');
$tpl->loadTemplatefile ('templates/index.tpl'truetrue);

// Front controller
$action $_GET["action"];
$id $_GET["id"];

switch (
$action) {
    case 
"showEnquete": {
        include_once(
"includes/showEnquete.php");
        
$content getContent();
        
$tpl->setVariable("CONTENT"$content);
        break;
        }

    default: {
        include_once(
"includes/overzicht.php");
        
$content getContent();
        
$tpl->setVariable("CONTENT"$content);
    }
}

$tpl->parse();
$tpl->show();

?>


So the program goes to showEnquete.php

showEnquete.php:

PHP Code:
<?php

function getContent() {
    require_once(
'MDB2.php');
    
    
// Template directory instellen
    
$tpl_main = new HTML_Template_IT('.');
    
$tpl_main->loadTemplatefile ('templates/showEnquete.tpl'falsefalse);
    
    
// Connectie instellen
    
$dsn "mysql://usr_enquete:enquete@localhost/enquete";
    
$mdb2 =&   MDB2::connect($dsnTRUE);
    if (
PEAR::isError($mdb2)) {
        die(
$mdb2->getMessage());
    }
    
    
// SQL
    
$res =& $mdb2->query('SELECT * FROM vragen WHERE eid="'.$_GET['id'].'"');
    
//$res2 =& $mdb2->query('SELECT * FROM enquetes WHERE eid="'.$_GET['id'].'"');
    
    // 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("VRAAG"$row['vraag']);
            
            
$tpl_main->parseCurrentBlock();
        }
    }

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

?>


And my showEnquete.tpl file:

Code:
<div id="wrapper">

	<h1>Enquete » {NAAM}</h1>
	
	<div id="content">
	
		<form id="enqueteForm" action="#">
		
			<table>
				<!-- BEGIN row -->
				<tr>
					<td>{VRAAG}</td>
				</tr>
				<tr>
					<td><input type="radio" id="antwoord1" name="antwoord" value="1">{ANTWOORD1}</td>
				</tr>
				<tr>
					<td><input type="radio" id="antwoord2" name="antwoord" value="2">{ANTWOORD2}</td>
				</tr>
				<tr>
					<td><input type="radio" id="antwoord3" name="antwoord" value="3">{ANTWOORD3}</td>
				</tr>
				<tr>
					<td><input type="radio" id="antwoord4" name="antwoord" value="4">{ANTWOORD4}</td>
				</tr>
				<tr>
					<td><input type="radio" id="antwoord5" name="antwoord" value="5">{ANTWOORD5}</td>
				</tr>
				<!-- END row -->
			</table>
			
                        <input type="submit" value="Antwoorden verzenden"  />

		</form>
		
	</div>

</div>


Any ideas of what I'm doing wrong?

Last edited by eLIX : July 24th, 2007 at 12:47 PM.

Reply With Quote
  #2  
Old July 24th, 2007, 02:13 PM
wiesemann wiesemann is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 152 wiesemann User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 26 m 25 sec
Reputation Power: 2
At first,
require_once('html/IT.php');
is wrong. It should be:
require_once 'HTML/Template/IT.php';

Now to your question: You call parseCurrentBlock() without having selected a block. Therefore, the internal current block property still has the '__global__' value, which causes the whole template to be parsed for each question.

=> Calling setCurrentBlock() before the loop should solve the problem.

Reply With Quote
  #3  
Old July 25th, 2007, 03:49 AM
eLIX eLIX is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 5 eLIX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by wiesemann
At first,
require_once('html/IT.php');
is wrong. It should be:
require_once 'HTML/Template/IT.php';

Now to your question: You call parseCurrentBlock() without having selected a block. Therefore, the internal current block property still has the '__global__' value, which causes the whole template to be parsed for each question.

=> Calling setCurrentBlock() before the loop should solve the problem.


Yea thnx I found it allready myself

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Elements after template block keep returning


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway