Eléphanteau du PHP |
20 Messages
16 juil. 2008, 13:40
Le code affiche en fait des produits de la même catégorie que celui qui est visualisé.
La partie qui ne fonctionne plus permet de ne pas afficher le produit visualisé mais bien les autres.
Euh ... j'espère que c'est clair pour vous .
voici le code de la page :
<?php
/*===============================================================================*/
define('MAX_THUMB_ROW', 4); # Number of maximum thumbs per row
define('MIN_THUMB_ROW', 1); # Minimum number of thumbs
define('TEXT_THUMB_BAR', 'Dans cette catégorie, nous vous proposons également :'); # text
/*================================================================================*/
#####################################
# DO NOT EDIT BELOW THIS POINT #
#####################################
# get the products in the current category
if ($current_category_id == 0) {
$cat_query = tep_db_query("select categories_id from " .TABLE_PRODUCTS_TO_CATEGORIES. " where products_id ='".$product_info['products_id']."'");
$cat = tep_db_fetch_array($cat_query);
$current_category_id = $cat['categories_id'];
$products_id = $product_info['products_id'];
}
$prod_query = "SELECT products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." WHERE categories_id='".$current_category_id."' AND products_id != '".$products_id."'";
# execute the query
$products_id_query = tep_db_query($prod_query);
$num_rows = mysql_num_rows($products_id_query);
IF ($num_rows > 0 ) {
# loop the array and populate the $prod_array with product ID's
$prod_array = array();
while($prods = tep_db_fetch_array($products_id_query)){
$prod_array[] = $prods['products_id'];
}
# free the result...clean as we go
tep_db_free_result($products_id_query);
# define the column list
$column_list = 'products_id, products_image, products_ordered';
# loop the $prod_array and start compiling the UNION query
$union = array();
foreach($prod_array as $index => $pID){
#$column_list = ( $index=0 ? 'SQL_CALC_FOUND_ROWS '.$column_list : $column_list);
$union[] = "SELECT ".$column_list." FROM ".TABLE_PRODUCTS." WHERE products_id='".$pID."' AND products_id != '".$products_id."' AND products_status='1'";
}
# implode the UNION query and get the final string
$union_str = implode(" UNION ", $union) . " ORDER BY products_ordered desc";
# unset some stuff...clean as we go
unset($prod_array, $union);
# include the class
include(DIR_WS_CLASSES . 'union_split_page_results.php');
# initiate the unionSplit class
# unionSplit( union query [string], max per row [int], current page [int], page parameter [string], explain the query [bool] )
$listing_split = new unionSplit($union_str, MAX_THUMB_ROW, (int)$_GET['page'], 'page', false);
# sanity check - if the number of returned products is greater than or equal to the minimum
if ( $listing_split->num_rows >= MIN_THUMB_ROW ){
?>
<!-- quick category thumb browser - by Chemo //-->
<?php
# set the column width dynamically
$width = (int)( ($listing_split->num_rows > MAX_THUMB_ROW) ? (1/MAX_THUMB_ROW*100) : (1/$listing_split->num_rows*100 ) );
#initialize the array - heading
$info_box_contents = array();
# set the array content - heading
$info_box_contents[] = array('align' => 'left', 'text' => ' ' . TEXT_THUMB_BAR);
# initialize the contentBoxHeading
new infoBoxHeading($info_box_contents, false, false);
#initialize the array - content
$info_box_contents = array();
# loop the query results from the split
while ( $tmp = tep_db_fetch_array($listing_split->query) ){
# get the name of the product
# you may choose to get this from a JOIN ... modify the above code and comment this out
$tmp['products_name'] = tep_get_products_name($tmp['products_id']);
# assign the data
$info_box_contents[0][] = array('align' => 'center',
'params' => 'class="smallText" valign="top" width="'.$width.'%"',
'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $tmp['products_id'] . ( isset($_GET['page']) && tep_not_null($_GET['page']) && is_numeric($_GET['page']) ? '&page=' . (int)$_GET['page'] : '') ) . ( isset($cPath) && tep_not_null($cPath) ? '&cPath='.$cPath : '' ) . '">' . tep_image(DIR_WS_IMAGES . $tmp['products_image'], $tmp['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $tmp['products_id']) . '">' . $tmp['products_name'] . '</a>');
}
# initialize the contentBox
new contentBox($info_box_contents);
# if the number of returned rows is greater than the max per row then output the nav links
if ( $listing_split->num_rows > MAX_THUMB_ROW ){
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td class="smallText"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
<td class="smallText" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
</tr>
</table>
<?php
} # end bracket for nav links block
?>
<!-- eof quick category thumb browser - by Chemo //-->
<?php
} # end bracket for if number returned products is greater than or equal to minimum
}
# If you would like to see how long it is taking to run the final UNION query for debugging
# uncomment the following line which will output the execution time
# echo $listing_split->execution_time;
?>