Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2013
    Posts
    811
    Plugin Contributions
    0

    Default read from database

    i put new field into admin categories. use calculator: = 0,1 or 2
    when i put this into tpl_product_display_.php, echo $calculator;
    Nothing happens, it does work on my other two sites.
    this is the code i placed into file
    Code:
    <!--bof Category Icon -->
    
        <?php if ($module_show_categories != 0) { ?>
            <?php
            $product_id = $_GET['products_id'];
            $sql = "select * from products_to_categories where products_id = " . (int) $product_id;
            $product_id = $db->Execute($sql);
    
            $sql = "select * from products where products_id = " . (int) $_GET['products_id'];
            $product = $db->Execute($sql);
    //        print_r($product->fields);
            $cat_id = $product_id->fields['categories_id'];
    //        $sql = "select * from categories where `categories_id`=$cat_id";
    //        $cat_search = $db->Execute($sql);
    //        $s_id = $cat_search->fields['parent_id'];
    
            $sql = 'select * from categories_description where categories_id=' . $cat_id;
            $cat_disc = $db->Execute($sql);
            $calculator = $cat_disc->fields['calculator_mode'];
    //        echo "Pa ID" . $pa_id . "<br>";
    //        echo "th ID" . $th_id . "<br>";
            /**
    
             * display the category icons
    
             */
            require($template->get_template_dir('/tpl_modules_category_icon_display.php', DIR_WS_TEMPLATE, $current_page_base, 'templates') . '/tpl_modules_category_icon_display.php');
            ?>
    
        <?php } ?>
    
        <!--eof Category Icon -->
    what do i need to do to read calculator_mode from categories descriptions field from db

  2. #2
    Join Date
    Jan 2013
    Posts
    811
    Plugin Contributions
    0

    Default Re: read from database

    not sure why that code did not work when it works on other sites, but i changed it to
    Code:
    <!--bof Category Icon -->
    <?php if ($module_show_categories != 0) {?>
    <?php
    /**
     * display the category icons
     */
    require($template->get_template_dir('/tpl_modules_category_icon_display.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_category_icon_display.php'); ?>
    <?php } ?>
    
    <?php
    $calculator = "";
    // categories_description
    $sql = "SELECT calculator_mode
            FROM " . TABLE_CATEGORIES_DESCRIPTION . "
            WHERE categories_id= :categoriesID
            AND language_id = :languagesID";
    
    $sql = $db->bindVars($sql, ':categoriesID', $current_category_id, 'integer');
    $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
    $categories_description_lookup = $db->Execute($sql);
    if ($categories_description_lookup->RecordCount() > 0) {
      $calculator = $categories_description_lookup->fields['calculator_mode'];
    }
    ?>
    <!--eof Category Icon -->
    seems to be working now.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: read from database

    There's a couple of potential reasons the other code didn't work: products_to_categories can return multiple category ids for a given product which would have required all categories to have the data applied, then there was the fact that categories_description is language based where it may be possible that there are extra records for the particular category.

    Basically as figured out (based on the code solution), it was possible that a category not associated with the current category and language could be the result.

    As a side note associated with this code, might suggest putting the determination of the value of $calculator into a main_template_vars or header_php related file in the associated includes/modules/pages/PAGE folder. This way the template file will just have the additional code to display the resulting variable. At any rate glad to see that the TABLE_ version of the table was used to ensure that the applicable DB_PREFIX was used.

    Good work figuring out the issue.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. separate non read-only attributes from read-only
    By solo_400 in forum General Questions
    Replies: 0
    Last Post: 19 Dec 2015, 10:52 AM
  2. Can I read in data from the database?
    By hutintheindies in forum General Questions
    Replies: 6
    Last Post: 27 Sep 2013, 06:20 PM
  3. Admin doesn't read database?
    By jarmolind in forum Basic Configuration
    Replies: 2
    Last Post: 9 Sep 2011, 02:00 PM
  4. Can no longer read database
    By tedpottel in forum Installing on a Linux/Unix Server
    Replies: 1
    Last Post: 24 Oct 2008, 11:08 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR