Page 1 sur 1

[resolu] Remplacer une info par une autre

Posté : 26 mars 2011, 23:30
par Mandes
Bonsoir à tous !

Je souhaite afficher une image qui indique aux visiteurs qu'il n'y a rien en cours (quand quelque chose l'est, l'image est remplacé par l'info en cours) Mon seul souci est que cette image s'ajoute à l'info lorsqu'en j'en créé une... (au lieu d'être supprimée et remplacée) Certainement un détail à modifier dans mon code mais vu que je me casse la tête depuis ce matin je sollicite votre aide. Merci à tous !
<?php
    }
?>
<td align="center" class="main"><?php echo '<a href="' . tep_href_link($navigation->path[$back]['page'], tep_array_to_string($navigation->path[$back]['get'], array('action')), $navigation->path[$back]['mode']) . '">' . tep_image_button('button_back.gif', IMAGE_BUTTON_CONTINUE_SHOPPING) . '</a>'; ?></td>
                  <td align="center" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . tep_image_button('button_checkout.gif', IMAGE_BUTTON_CHECKOUT) . '</a>'; ?></td>
				  <td align="center" class="main"><?php echo tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART); ?></td>
                <td width="0"><?php echo tep_draw_separator('pixel_trans.gif', '0', '0'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table>
       </td>
      </tr>
<?php
  } else {
?>
 <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '0', '1'); ?></td>
      </tr>
      <tr>
        <td valign="middle" align="center"><map name="image">
<area shape="rect" coords="0,0,522,547" href="http://www.monsite.com/catalog/index.php"></a>
<img src="/catalog/images/info.jpg" usemap="#image"></map></td>
            </tr>
<?php
  }
?>

Re: Remplacer une info par une autre

Posté : 27 mars 2011, 00:32
par moogli
salut,

code incomplet, et ne ressemble pas l'explication (pas de if).

Je dirais qu'il faut commencer par simplifier le code au maximum et juste tester la condition permettant d'afficher le texte ou l'image !

en gros
<?php
if ( condition vrai ) {
affiche le texte
}
else {
affiche l'image
}
?>
@+

Re: Remplacer une info par une autre

Posté : 27 mars 2011, 13:16
par Mandes
Merci pour cette réponse mais je ne peux pas repartir de zéro (mes compétences en php étant extrêmement limitées).
Tout est OK saut que mon image censée s'afficher uniquement lorsque qu'il n'y a pas d'info s'acharne à rester en place lorsque j'insert des infos... Merci ;-)

Re: Remplacer une info par une autre

Posté : 27 mars 2011, 16:30
par moogli
je t'ai donné la logique a utiliser, n'ayant pas le code on ne pas plus t'aider.


@+

Re: Remplacer une info par une autre

Posté : 28 mars 2011, 13:02
par macgawel
code incomplet, et ne ressemble pas l'explication (pas de if).
Par contre ça ressemble au problème (pas de if) :mrgreen:
Merci pour cette réponse mais je ne peux pas repartir de zéro (mes compétences en php étant extrêmement limitées).
Dans ce cas il faut poster dans "PHP débutant," pas "avancé" :evil:

Et sinon, vu qu'on n'est pas des devins, tu peux au moins nous dire quelle est l'image en question, parce que dans ton code il y en a plusieurs !

Re: Remplacer une info par une autre

Posté : 29 mars 2011, 23:41
par Mandes
Bonsoir et merci à tous.
Voici le code complet de la page.
Ce que j'essaye de faire : si FILENAME_SPECIALS ne contient rien alors on affiche nopromo.gif
Inversement si FILENAME_SPECIALS contient au moins un élément alors nopromo.gif disparait pour laisser la place à l'élément.
Sur le code affiché l'unique problème est que nopromo.gif persiste à rester sur la page que FILENAME_SPECIALS contienne un élément ou non. C'est tout ! (mais c'est déjà pas mal...) Merci de votre aide précieuse ;-)
<?php
/*
  $Id: specials.php,v 1.49 2003/06/09 22:35:33 hpdl Exp $
  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SPECIALS);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SPECIALS));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="4" cellpadding="4">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_specials.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '21'); ?></td>
      </tr>
<?php
  $specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added DESC";
  $specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIAL_PRODUCTS);

  if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            
            <!--<td align="center" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>-->
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
      </tr>
<?php
  }
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
<?php
    $row = 0;
    $specials_query = tep_db_query($specials_split->sql_query);
    while ($specials = tep_db_fetch_array($specials_query)) {
      $row++;

      echo '            <td align="center" width="100%" class="smallText1"><img src="gauche.jpg"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><img src="droite.jpg"><br><img src="ombre_shirt.jpg"><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . $specials['products_name'] . '</a><br><s>' . $currencies->display_price($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</s><span class="productSpecialPrice">' . $currencies->display_price($specials['specials_new_products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span></td>' . "\n";

      if ((($row / 1) == floor($row / 1))) {
?>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
          </tr>
          <tr>
<?php
      }
    }
?>
          </tr>
        </table></td>
      </tr>
<?php
  if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
      <tr>
        <td><br><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="smallText"><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>
            <td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
          </tr>
        </table></td>
      </tr>

<?php
  } else {
?>
 <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '0', '1'); ?></td>
      </tr>
      <tr>
        <td valign="middle" align="center"><map name="image">
<area shape="rect" coords="0,0,522,547" href="http://www.monsite.com/catalog/index.php"></a>
<img src="gauche.jpg"><img src="/catalog/images/nopromo.gif" usemap="#image"><img src="droite.jpg"></map><br><br></td>
            </tr>
<?php
  }
?>
    </table></td>
<!-- body_text_eof //-->
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
    </table></td>
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Re: Remplacer une info par une autre

Posté : 30 mars 2011, 21:29
par Ryle
Si ton image apparait systématiquement, c'est que php rentre systématiquement dans le else qui gère son affichage.
S'il exécute le else, c'est que l'instruction if() qui précède retourne une valeur à faux.
 if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
Ca veut dire que soit $specials_split->number_of_rows est systématiquement égal à 0 (ou moins), ou que PREV_NEXT_BAR_LOCATION est différent de 2 et de 3...

Tu peux donc soit, modifier ton if() pour changer le test, soit contrôler en amont ces deux variables pour voir ce qu'elles contiennent, et corriger leur contenu le cas échéant :)

Re: Remplacer une info par une autre

Posté : 30 mars 2011, 22:43
par Mandes
Salut et merci infiniment pour ton message. J'ai remplacé :

Code : Tout sélectionner

if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
par :

Code : Tout sélectionner

if (($specials_split->number_of_rows > 0)) {
J'ai également supprimé ce bloc sans trop savoir ce que ça implique (mais niveau affichage c'est plus propre...) :

Code : Tout sélectionner

<tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <!--<td align="center" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>--> </tr> </table></td> </tr>
Au final j'obtiens pile poil ce que je veux ! Mais est-ce ce bien ce qu'il fallait faire parce que j'ai d'énormes doutes sur mes compétences en php... Encore merci merci merci !!!

Re: Remplacer une info par une autre

Posté : 05 avr. 2011, 08:44
par Mandes
Ok... bon bah merki !!! ;-)