2

在另一个while循环中的while循环有一些问题

第一个 while 循环正在从 My SQL DB 表中获取产品的主要图像,而第二个 while 循环正在获取主要产品的其他屏幕截图。

这是我无法弄清楚的问题,当我只有一个来自 DB 的结果时,脚本可以正常工作,但是如果有多个主要产品,则它无法获取产品的主图像及其附加屏幕截图。

这是我的脚本:

<?
if ($free_pr_module_2 == 1) {
print<<<END
<div class="bonus">
<div class="specs-top mult">Featured $mult_pr_title</div>

END;

// multiple product image
 $mult_query = 'SELECT * FROM Files WHERE pageID = :id';
 $res = $db->prepare($mult_query);
 $res->execute(array(':id' => $pid));
while ($info = $res -> fetch()){
    $path_to_images = $image_path.$info['ImagePath'].DS;
    $mult_image_link = '<a href="'.$path_to_images.$info['templImage_lg'].'" rel="prettyPhoto[mu]" title="'.$info['templateTitle'].'"><img src="'.$path_to_images.$info['templateImage'].'" alt="'.$info['templateTitle'].' Screenshot'.'" width="'.$info['templimgwidth'].'" height="'.$info['templimgheight'].'" title="'.$info['templateTitle'].'"></a>';
    $mult_templTitle = '<h3>'.$info['templateTitle'].'</h3>';
    $mult_templText = $info['add_product_description'];
    $mult_templVersion = '<span class="tech"><b>VERSION</b> '.$info['templateVersion'].'</span>';
    $mult_templLicense = '<span class="tech"><b>LICENSE</b> '.$info['templLicense'].'</span>';
    $mult_download_but_path = SITE_DOMAIN.DS.DIR_FILES.DS;
    $mult_file_urlid = $info['urlid'];
    $mult_xls_button = ($info['xls'] == 1) ? '<div class="bb">
 <div class="bbl">Excel 2003(XP)<br><span>File: XLS</span></div>
 <div class="bb_button"><a class="bb_xls" href="'.$mult_download_but_path.'xls.php?urlid='.$mult_file_urlid.'" rel="nofollow" onClick="_gaq.push([\'_trackEvent\', \'Downloads\', \'XLS\', this.href.substr(29)]); user_notice(this,\'\'); return false;">Download</a></div>
</div>' : ('');
    $mult_xlsx_button = ($info['xlsx'] == 1) ? '<div class="bb">
 <div class="bbl">Excel 2007 +<br><span>File: XLSX</span></div>
 <div class="bb_button"><a class="bb_xlsx" href="'.$mult_download_but_path.'xlsx.php?urlid='.$mult_file_urlid.'" rel="nofollow" onClick="_gaq.push([\'_trackEvent\', \'Downloads\', \'XLSX\', this.href.substr(29)]); user_notice(this,\'\'); return false;">Download</a></div>
</div>' : ('');
    $mult_ots_button = ($info['ots'] == 1) ? '<div class="bb">
 <div class="bbl">OpenOffice<br><span>File: OTS</span></div>
 <div class="bb_button"><a class="bb_ots" href="'.$mult_download_but_path.'ots.php?urlid='.$mult_file_urlid.'" rel="nofollow" onClick="_gaq.push([\'_trackEvent\', \'Downloads\', \'OTS\', this.href.substr(29)]); user_notice(this,\'\'); return false;">Download</a></div>
</div>' : ('');
    $mult_gdocs_button = ($info['gdocs'] == NULL) ? '' : '<div class="bb">
 <div class="bbl">Google Docs<br></div>
 <div class="bb_button"><a class="bb_gdt" href="'.$info['gdocs'].'" rel="nofollow" target="_blank" onClick="_gaq.push([\'_trackEvent\', \'Downloads\', \'GDT\', this.href.substr(40)]);">Preview</a></div>
</div>';
    $mult_numbers_button = ($info['numbers'] == 1) ? '<div class="bb">
 <div class="bbl">Mac Numbers<br><span>File: NUMBERS</span></div>
 <div class="bb_button"><a class="bb_mac" href="'.$mult_download_but_path.'num.php?urlid='.$mult_file_urlid.'" rel="nofollow" onClick="_gaq.push([\'_trackEvent\', \'Downloads\', \'MCN\', this.href.substr(40)]); user_notice(this,\'\'); return false;">Download</a></div>
</div>' : ('');


print<<<END

<div class="mult_cont">
<div class="ss_left">

$mult_image_link

<div class="screnshot">
<span class="enlarge">1</span>
END;

// aditional images
$mult_main_image = "SELECT * FROM simages WHERE parentpageID = :id and main_img_show = '2'";
$res = $db->prepare($mult_main_image);
$res->execute(array(':id' => $pid));

$mult_num = 2;
while ($info = $res -> fetch()){
    $mult_post_img_link = $path_to_images.$info['main_img'];
    $mult_prphoto_id = $info['prphoto_id'];
    $mult_post_img_title = $info['main_img_title'];
    $mult_link_l = ($mult_num++);

print<<<END
<a href="$mult_post_img_link" class="enlarge" rel="prettyPhoto[$mult_prphoto_id]" title="$mult_post_img_title">$mult_link_l</a> 

END;
}

print<<<END
<div class="clear"></div>
</div>
</div>

$mult_templTitle
$mult_templText
<div class="clear"></div>
</div>
<div class="download">
<div class="mult_spec">
$mult_templVersion
$mult_templLicense
</div>

$mult_xls_button

$mult_xlsx_button

$mult_ots_button

$mult_gdocs_button

$mult_numbers_button

<div class="clear"></div>
</div>
END;
}

print<<<END
</div>
END;

}else
echo '';

?>

请耐心等待,因为我只学习 PHP/My SQL,而这实际上是我第一次尝试为我的网站创建有用的东西。

非常感谢您的帮助

4

1 回答 1

3

你正在覆盖你的变量。将内部循环更改$res为其他内容,例如。.$info$res2

于 2013-09-10T14:43:52.160 回答