Re: [SMARTY] {section} printing too many rows
| From: | Justin Mitchell | Date: | Fri, 10 Jan 2003 22:26:19 +0000 |
| Subject: | Re: [SMARTY] {section} printing too many rows | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7124@lists.php.net to get a copy of this message | ||
> > > Howdy. I'm having trouble with {section} printing one extra row
> > > than it's supposed to. Being that I've pulled another
> > > all-nighter, I wouldn't be surprised if it's a user error, but
> > > would someone take a quick look at the code to see what's going
> > > on? I'm stumped.
> > >
> > > index.php:
> > > // include stuff, define functions, connect to database removed
> > >
> > > $result = mysql_query("select * from servers");
> > > while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
> > > $i=$row[id]-1;
> > >
> > I've found that this happens when using a while loop with the
> mysql_fetch_*
> > functions. Either pop off the last member of the array after the while
> loop
> > or use mysql_num_rows and a for loop.
>
> I tried both of these methods, and each came up with the same result as
> before. When I popped of the last value of the array, then the last value
> was dropped, but I'd still have that extra blank row at the end when
smarty
> printed it out.
>
> FYI, I printed out the value of $num_rows and it came back with the
correct
> number of rows (not including this blank row that isn't actually in the
> array).
>
> $result = mysql_query("select * from servers");
> $num_rows = mysql_num_rows($result);
>
> for($i=0; $i<$num_rows; $i++) {
> $row = mysql_fetch_array($result);
>
> Any other ideas as to what might be going on? I'm stuck.
>
I figured it out. In one of the parts that I had cut out, I'd forgotten to
subscript the array. But, glad I know about the issues with using
mysql_fetch_array :-D.
Thanks!