請讓我先解釋一下我的問題。我有一個網上商店有很多產品,但也有很多類別。產品圖片從openicecat.biz導入,也是內容提供商。當沒有可用於特定產品描述或圖像,noimage.jpg顯示表演類圖像
有人提出,其從產品列表選取一個圖像,並將其作爲該類別一個圖像的代碼。 (如果可用) 麻煩來當一個類別都有一個子類使用圖像和沒有圖像的一個子類。將顯示noimage.jpg,而是顯示來自圖像子類別的圖像。
例如
catelog -> components -> card readers (no image) -> internal card reader (image)
-> external card reader (no image)
代碼段的設計,當有內部和外部的讀卡器兩張圖片,而不是當一個子類別沒有圖像只有一個圖像將顯示的方式。
我想要的是,例如,當子類別內部讀卡器的產品帶有圖像,並且子類別的外部讀卡器沒有圖像時,外部讀卡器的圖像顯示爲類別圖像的讀卡器。
例
catelog -> components -> card readers (image of internal card reader, instead of no image)
-> internal card reader (image)
-> external card reader (no image)
我希望你能明白我的意思。
這是代碼片段:
// Start auto fetch category image from product
if($categories['categories_image'] == "") {
$categories_img_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " p, products_to_categories pc WHERE p.products_id = pc.products_id AND pc.categories_id = '{$categories['categories_id']}' AND p.products_image IS NOT NULL order by p.products_id ASC");
if(tep_db_num_rows($categories_img_query) > 0) {
$categories_img = tep_db_fetch_array($categories_img_query);
$categories['categories_image'] = $categories_img['products_image'];
}
else {
$categories_img_parent_query = tep_db_query("select categories_id from categories WHERE parent_id = '{$categories['categories_id']}'");
while($categories_img_parent = tep_db_fetch_array($categories_img_parent_query)) {
$categories_img_query = tep_db_query("select products_image from " . TABLE_PRODUCTS . " p, products_to_categories pc WHERE p.products_id = pc.products_id AND pc.categories_id = '{$categories_img_parent['categories_id']}' AND p.products_image IS NOT NULL order by p.products_id ASC");
if(tep_db_num_rows($categories_img_query) > 0) {
$categories_img = tep_db_fetch_array($categories_img_query);
$categories['categories_image'] = $categories_img['products_image'];
}
}
}
}
// End auto fetch category image from product
誰能幫我完成這個片段?
btw1,它是爲osCommerce。
btw2,媽呀,我的allmost花40鍾抱怨並鍵入這個問題,這是值得金牌太(永恆的耐心勳章);-)
感謝您的回覆和sollution。我完全不熟悉php,能否向我解釋將代碼放在哪裏或要替換什麼? – Chris 2010-10-09 09:34:14
這個循環將代替條件塊開始,如果(tep_db_num_rows($ categories_img_query)> 0){... – 2010-10-09 09:36:37
你的意思是完整的(兩個,我相信): – Chris 2010-10-09 09:41:41