2

別の while ループ内の while ループに問題がある

最初の while ループは My SQL DB テーブルから製品のメイン画像をフェッチし、2 番目の while ループはメイン製品の他のスクリーンショットをフェッチしています。

ここに私が理解できない問題があります.DBからの結果が1つしかない場合、スクリプトは正常に機能していますが、複数の主要な製品がある場合、製品のメイン画像とその追加のスクリーンショットを取得できません.

これが私のスクリプトです:

<?
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