1
ccrstudioweb
Stop FOREACH looping using BREAK (PHP)

Hi,
The popunpoblog module block shows topics on a block by usage of a FOREACH. But I want the block to show only the first topic. To do so I need to stop the FOREACH loop using the BREAK comand. '

I read how to use it on PHP Files, but not in HTML files as it:



<{foreach item=blog_user from=$block.popnupblog}>
<table class="outer" cellspacing="0" cellpadding="5" width="100%">
<tr bgcolor="#f4f4f4">
<td bgcolor="#f4f4f4">
<font color="#999999"><strong><{$blog_user.last_update_s}></strong>
<{$blog_user.title}></font><br>
<font color="#000000" size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong><{$blog_user.last_title}></strong></font>
</td>
<td>&nbsp; </td><td>&nbsp; </td>
</tr>
<td colspan=4>
<{$blog_user.last_text|replace:"img":"img hspace='5'"}>
</td>
</tr><tr>
<td align="right"><{$blog_user.commentuname}> </TD>
<td colspan=3><{$blog_user.comment}></TD>
</tr>
<{/foreach}>


I thank any help!!
My Google Maps API3 and Xoops integration (Cool!):
http://www.esterecomendo.com.br/portal/

2
Catzwolf
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/7 18:43

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


try using <{break}> for this. before <{/foreach}>.

3
ccrstudioweb
Re: Stop FOREACH looping using BREAK (PHP)

I'd tried and received the following:
This page cannot be displayed due to an internal error.

You can provide the following information to the administrators of this site to help them solve the problem:

Error: Smarty error: [in db:popnupblog_block_1.html line 20]: syntax error: unrecognized tag 'break' (Smarty_Compiler.class.php, line 580)


I'd tried to erease the foreach as well and it works: It showed only one loop, but it was showed the first post, but I want to be shown the last one
My Google Maps API3 and Xoops integration (Cool!):
http://www.esterecomendo.com.br/portal/

4
JCDunnart
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/7 21:35

  • JCDunnart

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/7/1 5


Assign a name value then use the Smarty 'first' or 'last' construction.

e.g. Pseudo code
<{foreach item=blog_user from=$block.popnupblog [color=FF0000]name=foo[/color]}>
    <{if 
$smarty.foreach.foo.last}>
    ...
    <{else}>
    ...
    <{/if}>
<{/foreach}>


More details in the manual.

5
Dave_L
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/7 21:44

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


(JCDunnart beat me to it. )

6
ccrstudioweb
Re: Stop FOREACH looping using BREAK (PHP)

Hi, First I'm newbe on PHP, second this popunupblog is a very complex module and I could see that the variables used in the template above is used in other templates, if I chang it, it may inflict on changes in other template files.

Is it really neccessary to get the result wanted?
Is it possible to have the result wanted by changing only the html tamplete above?

I thought about BREAK, but I cant't understand -the template has the FOREACH comand, but when I add BREAK comand, there are error-. Is it possible that the PHP file restrict some comandas on template?

JCDunnart I read the manual, but if this were the only solution, I'll have a big job...

Thanks!!
My Google Maps API3 and Xoops integration (Cool!):
http://www.esterecomendo.com.br/portal/

7
Dave_L
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/8 1:29

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Smarty doesn't have a <{break}> tag; that's why it causes an error.

JCDunnart's method should do exactly what you want, except you can omit the <{else}> part:

<{foreach item=blog_user from=$block.popnupblog name=foo}>
    <{if 
$smarty.foreach.foo.last}>
    ...
    <{/if}>
<{/foreach}>


Just replace the "..." with the code currently in the body of the <{foreach}>.

8
ccrstudioweb
Re: Stop FOREACH looping using BREAK (PHP)

JCDunnart and Dave_L: I have no words... Thanks!
My Google Maps API3 and Xoops integration (Cool!):
http://www.esterecomendo.com.br/portal/

9
tzvook
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/8 8:14

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


That's some nice staff, but going with it a bit further ....

If I want to divide the block into 2 collums and I made it show 10 records altogether -
Will the following code give a result of 5 of the records in the first cell and the rest of the 10 in the second cell ?

<table>
<
tr>
    <
td><{foreach item=blog_user from=$block.popnupblog name=foo}>
    <{if 
$smarty.foreach.5.last}>
    ...
    <{/if}>
<{/foreach}></
td>
    <
td><{foreach item=blog_user from=$block.popnupblog name=foo}>
    <{if 
$smarty.foreach.6.first}>
    ...
    <{/if}>
<{/foreach}></
td>
</
tr>
</
table>


??????????????????

10
tzvook
Re: Stop FOREACH looping using BREAK (PHP)
  • 2007/4/8 8:24

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


ohh, yes I saw it's not the right code ....

the first 5 records should probably be:
<td><{foreach item=blog_user from=$block.popnupblog name=foo}>
    <{if 
$smarty.foreach.foo.5}>
    ...
    <{/if}>
<{/foreach}></
td>


But How can I start from record no. 6 till the last 10th ?

Login

Who's Online

236 user(s) are online (156 user(s) are browsing Support Forums)


Members: 0


Guests: 236


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits