Results 1 to 10 of 20

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    828
    Plugin Contributions
    0

    Default Help with Code needed.

    Hello All,

    I would like to use something like this in the tpl_product_info.php to dispaly different adds depending on click count. This works as a test page but when added to the product info I get a blank page. Im adding this to the bottom of the product info

    Code:
    $add1= "Read all about it. . . ";
    $add2= "Read about something else";
    
    session_start();
    $_SESSION['var'] = isset($_SESSION['var']) && $_SESSION['var'] <= 5 ? ($_SESSION['var'] + 1) : 1;
    
    if ($_SESSION['var'] == 1)
    {
    echo "$add1";
    }
    
    if ($_SESSION['var'] == 2)
    {
    echo "$add2";
    }
    
    and on and on . . .
    When this didn't work I tried adding to the begining

    Code:
    require($_SERVER["DOCUMENT_ROOT"] . "/2008_TestSite/includes/configure.php");
    $connection = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die(mysql_error());
    mysql_select_db(DB_DATABASE, $connection);
    but still I get nothing.

    Using version 1.3.8a Why won't this work?


    Thank you,
    John

  2. #2
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Help with Code needed.

    PHP Code:
    session_start(); 
    // session already started, no need for this
    PHP Code:
    $_SESSION['var'] = isset($_SESSION['var']) && $_SESSION['var'] <= ? ($_SESSION['var'] + 1) : 1
    Should be
    PHP Code:
    $_SESSION['var'] = (isset($_SESSION['var']) && $_SESSION['var'] <= 5) ? ($_SESSION['var'] + 1) : 1
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  3. #3
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: Help with Code needed.

    yellow1912,
    Good catch!!

    bumba000,
    Scrap Dreamweaver and use a good code editor that color codes php & errors
    Zen-Venom Get Bitten

  4. #4
    Join Date
    Feb 2007
    Location
    Pennsylvania
    Posts
    828
    Plugin Contributions
    0

    Default Re: Help with Code needed.

    O'kay. Here is my code that doesnt work, as basic as it gets. What's wrong?

    Code:
    <?php
    
    $_SESSION['var'] = (isset($_SESSION['var']) && $_SESSION['var'] <= 5) ? ($_SESSION['var'] + 1) : 1;  
    if ($_SESSION['var'] == 1)
    {
    echo "1";
    }
    
    if ($_SESSION['var'] == 2)
    {
    echo "2";
    }
    
    if ($_SESSION['var'] == 3)
    {
    echo "3";
    }
    
    if ($_SESSION['var'] == 4)
    {
    echo "4";
    }
    
    if ($_SESSION['var'] == 5)
    {
    echo "5";
    }
    
    if ($_SESSION['var'] == 6)
    {
    echo "6";
    }
    
    
    ?>
    Should I be including the query stuff above it?

    Dreamweaver highlights for php. I just don't know php at all. What editor would you recommend?

    Thanks,
    John

  5. #5
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Help with Code needed.

    1. Use switch or else if statement in this case. If you use 6 if(s), your code will have to check that value 6 times(when it only needs to do so once)

    2. Follow the tut here to turn on strict error mode and check the error code:
    https://www.zen-cart.com/tutorials/index.php?article=82

    3. For simple script like this, I use Notepad++, quick and easy to work with.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  6. #6
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: Help with Code needed.

    yours:
    Code:
    $_SESSION['var'] = (isset($_SESSION['var']) && $_SESSION['var'] <= 5) ? ($_SESSION['var'] + 1) : 1;
    yellow1912's
    Code:
    $_SESSION['var'] = isset($_SESSION['var']) && $_SESSION['var'] <= 5 ? ($_SESSION['var'] + 1) : 1;
    Red is open blue is close
    Zen-Venom Get Bitten

  7. #7
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Help with Code needed.

    Quote Originally Posted by kobra View Post
    yours:
    Code:
    $_SESSION['var'] = (isset($_SESSION['var']) && $_SESSION['var'] <= 5) ? ($_SESSION['var'] + 1) : 1;
    yellow1912's
    Code:
    $_SESSION['var'] = isset($_SESSION['var']) && $_SESSION['var'] <= 5 ? ($_SESSION['var'] + 1) : 1;
    Red is open blue is close
    Actually, it's the other way around, the second piece of code bumba000 posted used my suggested code.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

 

 

Similar Threads

  1. Canada Post Attribute Dimensions - code help needed
    By sae in forum Addon Shipping Modules
    Replies: 7
    Last Post: 12 Sep 2011, 06:03 PM
  2. Upgraded Code help needed
    By ryanb4614 in forum General Questions
    Replies: 0
    Last Post: 27 Jul 2010, 07:56 PM
  3. Error code 28, help needed urgently
    By yanachka in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 30 May 2010, 12:56 AM
  4. Code Needed For File Attachment Upload with PHP Form
    By bumba000 in forum General Questions
    Replies: 0
    Last Post: 28 Mar 2007, 07:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg