Page 1 sur 1

compatibilité PHP5

Posté : 16 juil. 2008, 01:36
par gabecity
Bonjour,

j'ai une requète qui fonctionne totalement sous php4
$prod_query = "SELECT products_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." WHERE categories_id='".$current_category_id."' AND products_id != '".$products_id."'";
Mais sous php5, la partie
AND products_id != '".$products_id."'
est ignoré ...
Pouvez-vous, s'il vous plait, m'expliquer pourquoi ...
Merci d'avance
Philippe

Posté : 16 juil. 2008, 01:51
par Sékiltoyai
Ca sent le problème de register_globals…
D'où vient cette variable ?

Posté : 16 juil. 2008, 03:21
par gabecity
d'une autre requète qui se trouve plus haut dans le code
Le code est tiré d'une contribution OSCommerce appelée thumbnail_category_browse.

Est-ce qu'un serveur qui était en php4 et qui est passé en php5 peut avoir changé de register_global ?

Posté : 16 juil. 2008, 08:54
par Sékiltoyai
Hé bien il nous faut un peu plus que simplement un bout de code.
Tu poses la question mais tu sais au moins ce que signifie "register_global" ?

Posté : 16 juil. 2008, 12:43
par chrislabricole
Effectivement, je suis du même côté que Sékiltoyai.
Perso, et il n'y a pas que moi, je déconseille FORTEMENT de d'activer register_global ;)
Ou au pire, ne pas l'utiliser...

si ton url est : index.php?variable=bonjour
si tu fais :
echo $variable;
avec register_global activé, ça donne "bonjour", et sans register_global ça ne donne rien du tout...
Si tu veux afficher "bonjour" sans utiliser register_global, tu dois faire :
echo $_GET['variable'];
c'est plus propre, plus compréhensif, est plus sécurisé à mes yeux ;)

Posté : 16 juil. 2008, 13:40
par gabecity
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' => '&nbsp;&nbsp;' . 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;
?>

Posté : 16 juil. 2008, 19:46
par Sékiltoyai
$product_info vient de nulle part… Il manque du code. Mais on ne va pas débugguer un logiciel complet pour toi. Adresse toi à ceux qui ont fait (mal apparemment) ce script…

Posté : 16 juil. 2008, 20:02
par dunbar
$product_info vient de nulle part… Il manque du code. Mais on ne va pas débugguer un logiciel complet pour toi. Adresse toi à ceux qui ont fait (mal apparemment) ce script…
Comme dit Sékiltoyai $product_info vient de nulle donc aussi $products_id puisque ici on remarque
que :
$products_id = $product_info['products_id'];

Posté : 16 juil. 2008, 23:22
par gabecity
ok je vais voir avec eu merci