Page 1 sur 1

mettre une condition à l'interieur d'une variable

Posté : 30 janv. 2006, 18:02
par storm61
Bonjour

J'aurais besoin d'une correction de code svp

je souhaiterais savoir si en php c'est possible de mettre une condition à l'interieur d'une variable

ce bout de code est issue d'un script OS Commerce

en clair je veux ecrire correctement l'extrait suivant c'est a dire metre la condition if a l'interieur de la variable $product_info_str car ma condition est à l'exterieur actuellement


merci bien
$product_info_str .= '<br><a class="info"  href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $product['products_description3'], MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT).'</a><br><br>'.$new_products['products_quantity'];
	if ($new_products['products_quantity'] > 0) { 
            echo tep_image(DIR_WS_IMAGES . 'stock_on.gif', TEXT_INFO_STOCK_ON, "10", "10").'&nbsp;'.TEXT_STOCK_ON;
            } else { 
            echo tep_image(DIR_WS_IMAGES . 'stock_on_order.gif', TEXT_INFO_STOCK_OUT, "10", "10").'&nbsp;'.TEXT_INFO_STOCK_OUT;
            }

Posté : 30 janv. 2006, 18:36
par alexbad
Non, c'est impossible, par contre, il y a bel et bien une solution à ton problème, un exemple:
<?php
if ($new_products['products_quantity'] > 0)
{
$ajout = 'Condition 1';
}
else
{
$ajout = 'Condition 2';
}

$variable = 'Ma variable avec un contenu "variable" : ' . $ajout;
?>

Posté : 30 janv. 2006, 18:44
par storm61
ok merci pour le tuyau

ca marche ca
$product_info_str .= '<br><a class="info"  href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $new_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $new_products['products_image'], $product['products_description3'], MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT).'</a><br><br>';
	if ($new_products['products_quantity'] > 0) { 
        $product_info_str .= tep_image(DIR_WS_IMAGES . 'stock_on.gif', TEXT_INFO_STOCK_ON, "10", "10").'&nbsp;'.TEXT_STOCK_ON;
            } else { 
        $product_info_str .= tep_image(DIR_WS_IMAGES . 'stock_on_order.gif', TEXT_INFO_STOCK_OUT, "10", "10").'&nbsp;'.TEXT_INFO_STOCK_OUT;
            }