4 Replies Latest reply on Oct 22, 2007 3:24 PM by (Steve_Guluk)

    Help - PHP elseif

      This is driving me crazy and if no one can help is there a friendly PHP forum where I can bounce ideas of others?

      Here's the problem.. I'm trying to show a button in place of an Add to Cart button, IF that model_id is stored in a cart table.

      Here is the snippet of code I am using... The IF operator checks to see if there is a cookie present. If not it allows displaying the basic "add to cart" button that creates a cookie and uses the session id as the cookie tracking id. It also saves the model_id with a cookieId which allows tracking the experience independently for each user.

      <PHP


      if (! isset ( $_COOKIE[ 'cartId' ] )) {



      echo ("<a href=\"#\">") ;

      echo ("<IMG src=\"WA_eCart/Images/Pacifica/Btn2_EN_addtocart.gif\" alt=\"Add
      to cart\" width=\"83\" height=\"27\" border=\"0\"")
      ;

      echo ("onMouseDown=\"MM_openBrWindow('cart.php?action=add_item&id=")
      ;

      echo $row_rsModel [ 'model_id' ] ;

      echo ("','cart','scrollbars=yes,width=300,height=300')\"></a>no
      cke") ; }



      elseif ($row_rsModel [ 'model_id' ] == $row_rsCart [ 'itemId' ]) {

      echo ("<img src=\"WA_eCart/Images/Pacifica/Btn2_EN_inCart.gif\" width=\"83\" height=\"27\" border=\"0\">");

      }



      else {

      echo ("<a href=\"#\">") ;

      echo ("<IMG src=\"WA_eCart/Images/Pacifica/Btn2_EN_addtocart.gif\" alt=\"Add
      to cart\" width=\"83\" height=\"27\" border=\"0\"")
      ;

      echo ("onMouseDown=\"MM_openBrWindow('cart.php?action=add_item&id=")
      ;

      echo $row_rsModel [ 'model_id' ] ;

      echo ("','cart','scrollbars=yes,width=300,height=300')\"></a>cke
      yes") ;

      }

      ?>



      http://www.retailertoolkit.com/inventest.php
      (Refresh your page after adding to cart)

      I have two recordsets. rsModel that selects all the available models to display in a repeat region.
      The next recordset (rsCart) only lives if there is a cookie found.

      The aforementioned code works to show the add to cart button if no cookie is present (allows the start of the tracking) and also the ELSE area works where if a cookie IS present if shows the same add to cart button.

      But where I have trouble is the elseif that I have coded to check if the stored cartID equals the model_id that is generated via the repeat region. If a match is found that would mean there is an entry in the DB so that item is already added to the cart and does not need the button that adds and item.

      Reference:
      elseif ($row_rsModel [ 'model_id' ] == $row_rsCart [ 'itemId' ]) {

      I'm thinking my problem is not so much code but logic in getting the comparison of value between recordsets but just the proper way to attack this problem.

      Also there is a problem where I can not execute the means to use the recordset "rsCart" until there is an item in the cart and the cookie present. That's the logic/reality that causes problems.

      Anyone?
        • 1. Re: Help - PHP elseif
          Günter Schenk Level 4
          Hi Steve,

          is this the WebAssist eCard ?

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Help - PHP elseif
            Level 1
            Hi Günter,
            No way! Too much overhead with trying to use just a little of their cart. It's all built buy hand using basic DW data functions and ADDT. I'm getting to the point of hand coding the individual queries since I did not find any ADDT or otherwise extensions that would do what I was looking for.
            • 3. Re: Help - PHP elseif
              Günter Schenk Level 4
              Hi Steve,

              just an idea and without going to any details, what could be embarrasing, lol :-)

              Rather than creating two separate queries, how about creating a JOIN query which integrates the desired columns from the secondary table -- that should be much easier to handle, otherwise you´d have to manually create a sub-query, what´s a little weird to do

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: Help - PHP elseif
                Level 1
                Would the hybrid recordset be able to resolve when there is no value found in the cart table?

                What's giving me the most problem is that I need to consider and handle the case when there is no data (cart session id) available and the other case is when there is data, and then check to see if the available data matches that rendered in the repeat region value.

                Maybe I'm trying to do all this in a more precise manner than is available with simple programming. I may need to grab ALL the values and then sort them against my Var if available...