[英]php while loop inside while loop
在另一個while循環中使用while循環時遇到一些問題
第一個while循環從My SQL DB表中獲取產品的主圖像,第二個while循環從主產品中獲取其他屏幕截圖。
這是我無法確定的問題,當我只有一個數據庫結果時,腳本可以正常工作,但是如果有多個主要產品,則腳本無法獲取產品的主圖像及其附加屏幕截圖。
這是我的腳本:
<?
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 / SQL,而這實際上是我第一次嘗試為我的網站創建有用的東西。
您的幫助非常值得
您正在覆蓋變量。 將$res
和$info
從內部循環更改$res
其他內容。 $res2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.