开发者

php $count - Undefined variable:

I have this code that I want to insert a div clear class the it reaches the 5th column:

<div class="grid<?php $count++; if ($count == 5) ?>">  
<?php if ($count == 5) { $count = 0; echo '<div class="clearit"></div>'; } ?>

It works but I am g开发者_开发技巧etting this error that I want to get rid of:

Notice: Undefined variable: count  in....template/catalog/product/layout.phtml on line 40

where line 40 is <div class="grid<?php $count++; if ($count == 5) ?>">

I can't tell where has gone wrong with my limited PHP knowledge


It is because you have not declared your variable. If you add $count = 0; to the top of your PHP file the error will go away as you have declared the variable.

You should also note that this has nothing to do with Zend Framework.


It is better to do that with CSS and not with markup or server side scripting. Let me give you an example:

.grid:nth-child(5n+5), .grid.fifth-child { clear: both; }

It's not supported in every browser so you can use jQuery to fix that:

$('.grid:nth-child(5n+5)').addClass('fifth-child');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜