使用此代码,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 />';
}
答案 0 :(得分:1)
在foreach之前移动它,或者它始终重新初始化$id
$id = 1;
foreach ($message['attachment'] as $attachment)
{
答案 1 :(得分:0)
现在,每次循环播放数组时都要设置$id = 1
foreach ($message['attachment'] as $attachment) {
// ...
$id = 1;
// ...
}
为了正确地增加它,你需要将它放在循环
之前$id = 1;
foreach ($message['attachment'] as $attachment) {
// ...
}