[英]Loop through images not working
使用此代码,ID始终为1。我希望它在每次遍历消息时都添加+1。
如ex1,ex2,ex3等,等等。
我不知道怎么了。 有人可以帮忙吗?
foreach ($message['attachment'] as $attachment)
{
if ($attachment['is_image'])
{
if ($attachment['thumbnail']['has_thumb'])
echo '<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" border="0" class="opplastetbilde"/></a><br />';
else
$id = 1;
if ($id < 10) {
echo '<span class="zoom" id="ex' . $id . '"><img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" border="0" class="opplastetbilde"/></span><br />';
$id++;
}
}
echo '<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" /> ' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
}
在foreach之前移动它,否则它总是重新初始化$id
$id = 1;
foreach ($message['attachment'] as $attachment)
{
现在,您每次遍历数组时都设置$id = 1
foreach ($message['attachment'] as $attachment) {
// ...
$id = 1;
// ...
}
为了适当地增加它,您需要将其放置在循环之前
$id = 1;
foreach ($message['attachment'] as $attachment) {
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.