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 25th, 2007, 02:57 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
FetchRow() gives one row too many

Hi,

When I'm filling up a table with the fetchRow() method, I seem to get one row too many (with no data in it)

Here's the code:

PHP Code:
while (($row $res->fetchRow(MDB2_FETCHMODE_ASSOC))) {
            
$einddatum $row['geldigheid'];
            
$datum date('Y-m-d');
            
$idCounter++;
            
            if(
$datum $einddatum) {
                
$tpl_main->setVariable("ID""index.php?action=showEnquete&id=$idCounter");
                
$tpl_main->setVariable("NAAM"$row['naam']);
                
$tpl_main->setVariable("AANTALVRAGEN"$row['aantalvragen']);
                
$tpl_main->parseCurrentBlock();
            }
        } 


And the result is:

Code:
.
..
...
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>
				<td class="leftColumn"><a href="index.php?action=showEnquete&id=23">nu zou't moeten werken!</a></td>
				<td>10</td>
			</tr>
			
			<tr>

				<td class="leftColumn"><a href="index.php?action=showEnquete&id=24">Laatste Test normaal gezien</a></td>
				<td>11</td>
			</tr>
			
			<tr>
				<td class="leftColumn"><a href=""></a></td>
				<td></td>
			</tr>


As you can see at the bottom there's an empty row.
How can this happen?

Reply With Quote
  #2  
Old July 26th, 2007, 02:17 AM
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
Maybe you call parseCurrentBlock() or parse() another time after the loop?

Reply With Quote
  #3  
Old July 26th, 2007, 11:56 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
Maybe you call parseCurrentBlock() or parse() another time after the loop?


Nope not doing that
Here's the full code:

PHP Code:
<?php

function getContent() {
    require_once(
'MDB2.php');
    
    
$idCounter 0;
    
    
// Template directory instellen
    
$tpl_main = new HTML_Template_IT('.');
    
$tpl_main->loadTemplatefile ('templates/overzicht.tpl'falsefalse);
    
$tpl_main->setCurrentBlock("row");
    
    
// 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 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))) {
            
$einddatum $row['geldigheid'];
            
$datum date('Y-m-d');
            
$idCounter++;
            
            if(
$datum $einddatum) {
                
$tpl_main->setVariable("ID""index.php?action=showEnquete&id=$idCounter");
                
$tpl_main->setVariable("NAAM"$row['naam']);
                
$tpl_main->setVariable("AANTALVRAGEN"$row['aantalvragen']);
                
$tpl_main->parseCurrentBlock();
            }
        }
    }

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

?>

Reply With Quote
  #4  
Old July 26th, 2007, 01:55 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
The code looks okay. Can you show us your template, please?

Reply With Quote
  #5  
Old July 26th, 2007, 02:29 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
Quote:
Originally Posted by wiesemann
The code looks okay. Can you show us your template, please?


Code:
<div id="wrapper">

	<h1>Enquetes Overzicht</h1>
	
	<div id="content">
	
		<p>
			Klik op de naam van de enquete om deze in te vullen
		</p>
		
		<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="{ID}">{NAAM}</a></td>
				<td>{AANTALVRAGEN}</td>
			</tr>
			<!-- END row -->
		</table>
		
	</div>
	
</div>

Reply With Quote
  #6  
Old July 26th, 2007, 03:03 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
The template also looks right.

Two ideas for debugging:
- add error_reporting(E_ALL); at the beginning of your script
- add var_dump($row); in your while loop to see if $row really contains something

Reply With Quote
  #7  
Old July 26th, 2007, 04:06 PM
cwf's Avatar
cwf cwf is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 354 cwf User rank is Private First Class (20 - 50 Reputation Level)cwf User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 7 h 7 m 19 sec
Reputation Power: 2
Because the extra output does not contain the static portion of the string being put into the ID variable - index.php?action=... the extra output is not coming from the code in that loop in that function. Something else in your code is causing a reference to the template with completely empty variables and causing that empty output.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > FetchRow() gives one row too many


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 2 hosted by Hostway