Database Driven Website Hosting Issues

  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

I have a website that is mySQL database driven (www_coinsupplyzone_com), but it is so slow to load most of the time. Some pages take 30+ seconds to load, while other times that same page will load in less than a second.

I am currently using "inmotionhosting" as my hosting company. I did a lot of research before I pulled the trigger on them, but I was wondering if there was such a thing as a hosting company that specializes in database driven sites? Or if there was a way to help speed up my database access times? I know a pretty good amount about HTML and CSS, but when it comes to databases I'm a beginner.

Any help will be appreciated, thanks.......John
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9087
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

You may want to ask your webhost if they know of any reason your website is loading slow at times. There could be many things causing your issue, and I will list a few of them.

The first could be your webhost is at fault. It is possible that your webhost either has too many users on their servers which causes it to bog down at times adversely affecting you. It could also be that your webhost has not configured your MySQL database optimally which could cause it to have poor performance at times.

The second could be that you are at fault. Are you creating your own MySQL queries by writing the code yourself? Or are you use software that has already been written by someone else? The reason I ask is because if you do not carefully craft your SQL queries you could easily execute some very poor performing queries that search millions of records which would take a long time to execute. If you have written your own SQL queries you might want to go through each one and execute them in phpMyAdmin or whatever your favorite method is, and put the word EXPLAIN in front of the query. This can tell you all sorts of things from the type of search the query is using, to how many records it is having to search through to give you its results. It can also indicate to you if you have not setup your indexes correctly which could speed of your queries a great deal. So for example if I had a query like this that gives me one result:

SQL Code: [ Select ]
SELECT *
FROM `phpbb_posts`
WHERE `post_id` =123456
  1. SELECT *
  2. FROM `phpbb_posts`
  3. WHERE `post_id` =123456


you could find information about it by placing the explain word in the front:

SQL Code: [ Select ]
EXPLAIN SELECT *
FROM `phpbb_posts`
WHERE `post_id` =123456
  1. EXPLAIN SELECT *
  2. FROM `phpbb_posts`
  3. WHERE `post_id` =123456


Your webhost may work with you to help you diagnose your problem, or if they do not seem like much help you can always move to a new webhost, such as Ozzu ;)

A few threads at Ozzu which may be helpful:

MySQL Limits

What are a lot of MySQL queries per page?

MySQL Table With Millions of Entrees
  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

I contacted my host regarding this issue they keep saying that it is most likely an issue with my internet and my site loads fine on their end. What makes no sense though is that during the day the pages take forever to load, but at night they load in less than a second or two.

I did the following in my hosting control panel: "Compress the specified MIME types" (text/html text/plain text/xml), but that is pretty much all i know how to do.

I did not write the code myself, it is my shopping cart ViArt that did that for me. I'll check out those other threads, thanks.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9087
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Just curious, does your website get a great deal of traffic?

Typically web servers do get more busy during the day, but if your website doesn't get a large amount of traffic, that doesn't mean someone else on your server isn't which is bogging things down. It is really hard to guess without getting on their server and diagnosing what is going on, there could be numerous reasons causing this.

As far as it being your local connection, that is always possible as well. Let's say for instance you have a cable connection, its possible that during the day you have a few people in your local area that are using up all of the available bandwidth thus making things appear slower for you. Again this is all just speculation, it could very well be your host too. A good way to test this, try visiting some other websites when your site appears slow and see if the entire Internet is slow for you, or just your website. If it is just your website, then it is most likely your web host, or something wrong with your website.
  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

My site gets no more than 20 visitors a day right now, so it must be the server load during the day messing with me.

I am going to see if I can create static HTML pages with my database as that may speed things up for me. I just have too many queries running per page.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9087
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Having too many queries running per page could really slow a page load down. Many times by just redoing your SQL queries and trying to make things more efficient you can cut down how many are running per page. For instance, a long time ago Ozzu had around 30 SQL calls per page, and by redoing everything and being more smart on how every query was called I remember I was able to get it down to around 10 per page, and all of the same information was still retrieved.

Spots to watch out for are loops which call the same query over and over. So for instance if you had an array of 10 values of which you wanted to retrieve results via SQL for each value, you could run a loop and run 10 separate SQL statements, or you could run 1 SQL statement and search for all of the ids within that statement and return the same results. Usually, the second way is much more efficient.
  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

I think that is my problem exactly, my programmers told me that my site has up to a couple hundred queries per page. I do not know if it is possible for me to "un-loop" my database to shorten up the queries, or even where to start.

I placed an example of the database I use for my shopping cart on my ftp:

www_coinsupplyzone_com/database_example.sql

If one of you could look at it and tell me if it is possible to "condense" it I would be most appreciative. Then I can look into it into further detail on how to hopefully shorten up some of these queries.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9087
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Part of the problem could be your database structure, so thanks for posting that. However, typically the problem for how many SQL queries you execute isn't due to your database itself, but how your are creating queries in your programming code to access and retrieve results from your database. Do you have an example of some of the code that runs one of your slow pages that includes some SQL queries?
  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

Here are two bits of code from my site. The first is for calling the category descriptions and the other is for calling the category list:

Code: [ Select ]
<?php

    $desc_image = get_setting_value($vars, "category_description_image", 3);
    $desc_type = get_setting_value($vars, "category_description_type", 2);

    $sql = " SELECT * ";
    $sql .= " FROM " . $table_prefix . "categories ";
    $sql .= " WHERE category_id = " . $db->tosql($category_id, INTEGER);
    $db->query($sql);
    if ($db->next_record())
    {
        $category_name = get_translation($db->f("category_name"));
        $description = "";
        if ($desc_type == 2) {
            $description = get_translation($db->f("full_description"));
        } elseif ($desc_type == "full_description_2" || $desc_type == "full_description2") {
            $description = get_translation($db->f("full_description_2"));
        } elseif ($desc_type == 1) {
            $description = get_translation($db->f("short_description"));
        } elseif ($desc_type == "feature_1" || $desc_type == "feature1") {
            $description = get_translation($db->f("feature_1"));
        } elseif ($desc_type == "feature_2" || $desc_type == "feature2") {
            $description = get_translation($db->f("feature_2"));
        } elseif ($desc_type == "feature_3" || $desc_type == "feature3") {
            $description = get_translation($db->f("feature_3"));
        } elseif ($desc_type == "feature_4" || $desc_type == "feature4") {
            $description = get_translation($db->f("feature_4"));
        } elseif ($desc_type == "feature_5" || $desc_type == "feature5") {
            $description = get_translation($db->f("feature_5"));
        } elseif ($desc_type == "feature_6" || $desc_type == "feature6") {
            $description = get_translation($db->f("feature_6"));
        } elseif ($desc_type == "feature_7" || $desc_type == "feature7") {
            $description = get_translation($db->f("feature_7"));
        }
        $image = ""; $image_alt = "";
        if ($desc_image == 3) {
            $image   = $db->f("image_large");
            $image_alt = get_translation($db->f("image_large_alt"));
        } elseif ($desc_image == 2) {
            $image   = $db->f("image");
            $image_alt = get_translation($db->f("image_alt"));
        }

        if (!strlen($image)) {
            $image_exists = false;
        } elseif (!image_exists($image)) {
            $image_exists = false;
        } else {
            $image_exists = true;
        }

        if (strlen($description) || $image_exists)
        {
            $html_template = get_setting_value($block, "html_template", "block_category_description.html");
         $t->set_file("block_body", $html_template);

            if ($image_exists) {
                if (preg_match("/^http\:\/\//", $image)) {
                    $image_size = "";
                } else {
                    $image_size = @GetImageSize($image);
                    if (isset($restrict_categories_images) && $restrict_categories_images) { $image = "image_show.php?category_id=".$category_id."&type=large"; }
                }
                if (!strlen($image_alt)) { $image_alt = $category_name; }
                $t->set_var("alt", htmlspecialchars($image_alt));
                $t->set_var("src", htmlspecialchars($image));
                if (is_array($image_size)) {
                    $t->set_var("width", "width=\"" . $image_size[0] . "\"");
                    $t->set_var("height", "height=\"" . $image_size[1] . "\"");
                } else {
                    $t->set_var("width", "");
                    $t->set_var("height", "");
                }
                $t->sparse("image_large_block", false);
            } else {
                $t->set_var("image_large_block", "");
            }
     
            $t->set_var("category_name", $category_name);
            $t->set_var("full_description", $description);

            $block_parsed = true;
            $t->parse("block_body", false);
        }
    }

?>
  1. <?php
  2.     $desc_image = get_setting_value($vars, "category_description_image", 3);
  3.     $desc_type = get_setting_value($vars, "category_description_type", 2);
  4.     $sql = " SELECT * ";
  5.     $sql .= " FROM " . $table_prefix . "categories ";
  6.     $sql .= " WHERE category_id = " . $db->tosql($category_id, INTEGER);
  7.     $db->query($sql);
  8.     if ($db->next_record())
  9.     {
  10.         $category_name = get_translation($db->f("category_name"));
  11.         $description = "";
  12.         if ($desc_type == 2) {
  13.             $description = get_translation($db->f("full_description"));
  14.         } elseif ($desc_type == "full_description_2" || $desc_type == "full_description2") {
  15.             $description = get_translation($db->f("full_description_2"));
  16.         } elseif ($desc_type == 1) {
  17.             $description = get_translation($db->f("short_description"));
  18.         } elseif ($desc_type == "feature_1" || $desc_type == "feature1") {
  19.             $description = get_translation($db->f("feature_1"));
  20.         } elseif ($desc_type == "feature_2" || $desc_type == "feature2") {
  21.             $description = get_translation($db->f("feature_2"));
  22.         } elseif ($desc_type == "feature_3" || $desc_type == "feature3") {
  23.             $description = get_translation($db->f("feature_3"));
  24.         } elseif ($desc_type == "feature_4" || $desc_type == "feature4") {
  25.             $description = get_translation($db->f("feature_4"));
  26.         } elseif ($desc_type == "feature_5" || $desc_type == "feature5") {
  27.             $description = get_translation($db->f("feature_5"));
  28.         } elseif ($desc_type == "feature_6" || $desc_type == "feature6") {
  29.             $description = get_translation($db->f("feature_6"));
  30.         } elseif ($desc_type == "feature_7" || $desc_type == "feature7") {
  31.             $description = get_translation($db->f("feature_7"));
  32.         }
  33.         $image = ""; $image_alt = "";
  34.         if ($desc_image == 3) {
  35.             $image   = $db->f("image_large");
  36.             $image_alt = get_translation($db->f("image_large_alt"));
  37.         } elseif ($desc_image == 2) {
  38.             $image   = $db->f("image");
  39.             $image_alt = get_translation($db->f("image_alt"));
  40.         }
  41.         if (!strlen($image)) {
  42.             $image_exists = false;
  43.         } elseif (!image_exists($image)) {
  44.             $image_exists = false;
  45.         } else {
  46.             $image_exists = true;
  47.         }
  48.         if (strlen($description) || $image_exists)
  49.         {
  50.             $html_template = get_setting_value($block, "html_template", "block_category_description.html");
  51.          $t->set_file("block_body", $html_template);
  52.             if ($image_exists) {
  53.                 if (preg_match("/^http\:\/\//", $image)) {
  54.                     $image_size = "";
  55.                 } else {
  56.                     $image_size = @GetImageSize($image);
  57.                     if (isset($restrict_categories_images) && $restrict_categories_images) { $image = "image_show.php?category_id=".$category_id."&type=large"; }
  58.                 }
  59.                 if (!strlen($image_alt)) { $image_alt = $category_name; }
  60.                 $t->set_var("alt", htmlspecialchars($image_alt));
  61.                 $t->set_var("src", htmlspecialchars($image));
  62.                 if (is_array($image_size)) {
  63.                     $t->set_var("width", "width=\"" . $image_size[0] . "\"");
  64.                     $t->set_var("height", "height=\"" . $image_size[1] . "\"");
  65.                 } else {
  66.                     $t->set_var("width", "");
  67.                     $t->set_var("height", "");
  68.                 }
  69.                 $t->sparse("image_large_block", false);
  70.             } else {
  71.                 $t->set_var("image_large_block", "");
  72.             }
  73.      
  74.             $t->set_var("category_name", $category_name);
  75.             $t->set_var("full_description", $description);
  76.             $block_parsed = true;
  77.             $t->parse("block_body", false);
  78.         }
  79.     }
  80. ?>


Code: [ Select ]
<?php

    include_once("./includes/products_functions.php");

    include_once("./messages/" . $language_code . "/cart_messages.php");
    include_once("./messages/" . $language_code . "/reviews_messages.php");
    include_once("./messages/" . $language_code . "/download_messages.php");

    $user_id = get_session("session_user_id");        
    $user_info = get_session("session_user_info");
    $user_type_id = get_setting_value($user_info, "user_type_id", "");

    $friendly_urls = get_setting_value($settings, "friendly_urls", 0);
    $friendly_extension = get_setting_value($settings, "friendly_extension", "");
    $columns = get_setting_value($vars, "categories_columns", 1);
    $categories_type = get_setting_value($vars, "categories_type");

    $category_id = get_param("category_id");
    $search_category_id = get_param("search_category_id");
    $search_string = get_param("search_string");
    $is_search = strlen($search_string);

    if ($is_search && $search_category_id) { $category_id = $search_category_id; }

    $item_id = get_param("item_id");
    if (!strlen($category_id)) {
        if (strlen($item_id)) {
            $category_id = get_db_value("SELECT category_id FROM " . $table_prefix . "items_categories where item_id=".$db->tosql($item_id, INTEGER));
        } else {
            $category_id = "0";
        }
    }

    $category_id = intval($category_id);
    
    $t->set_var("products_href",  get_custom_friendly_url("products.php"));
    $t->set_var("list_href",    get_custom_friendly_url("products.php"));
    $t->set_var("details_href",   get_custom_friendly_url("product_details.php"));
    $t->set_var("top_category_name",PRODUCTS_TITLE);
    $t->set_var("category_rss", "");

    $list_page = get_custom_friendly_url("products.php");
    $list_url = new VA_URL($list_page);

    $categories_image = get_setting_value($vars, "categories_image");
    
    if ($categories_type == 1 || $categories_type == 2) {
        if (file_exists("images/".$settings["style_name"]."/category_image.gif")) {
            $image_tree_top = "images/".$settings["style_name"]."/category_image.gif";
        } else {
            $image_tree_top = "images/category_image.gif";
        }
        $html_template = get_setting_value($block, "html_template", "block_categories_catalog.html");
     $t->set_file("block_body", $html_template);
        $t->set_var("catalog_sub",     "");
        $t->set_var("catalog_sub_more",  "");
        $t->set_var("catalog_rows",    "");
        $t->set_var("catalog_top",     "");
        $t->set_var("catalog_description", "");

        $categories_ids = VA_Categories::find_all_ids("c.parent_category_id=" . $db->tosql($category_id, INTEGER), VIEW_CATEGORIES_PERM);
        if (!$categories_ids) return;
        $allowed_categories_ids = VA_Categories::find_all_ids("c.parent_category_id=" . $db->tosql($category_id, INTEGER), VIEW_CATEGORIES_ITEMS_PERM);
                
        if ($categories_type == 2) {
            $sub_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")", VIEW_CATEGORIES_PERM);
            if (!$sub_categories_ids)
                $categories_type = 1;
        }

        if ($categories_type == 1) {
            $sql = " SELECT category_id AS top_category_id, category_name AS top_category_name, a_title AS top_a_title, ";
            $sql .= " short_description, friendly_url AS top_friendly_url, ";
            $sql .= " image, image_alt, image_large, image_large_alt ";
            $sql .= " FROM " . $table_prefix . "categories ";
            $sql .= " WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")";    
            $sql .= " ORDER BY category_order, category_name ";
        } else {
            // show categories as catalog
            $allowed_sub_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")", VIEW_CATEGORIES_ITEMS_PERM);                        
            $sql = " SELECT c.category_id AS top_category_id,c.category_name AS top_category_name, ";
            $sql .= " c.friendly_url AS top_friendly_url, c.a_title AS top_a_title, ";
            $sql .= " c.image, c.image_alt, c.image_large, c.image_large_alt, ";
            $sql .= " s.category_id AS sub_category_id,s.category_name AS sub_category_name, ";
            $sql .= " s.friendly_url AS sub_friendly_url, s.a_title AS sub_a_title ";
            $sql .= " FROM (" . $table_prefix . "categories c ";
            $sql .= " LEFT JOIN " . $table_prefix . "categories s ";            
            if ($sub_categories_ids) {
                $sql .= " ON (c.category_id=s.parent_category_id ";            
                $sql .= " AND s.category_id IN (" . $db->tosql($sub_categories_ids, INTEGERS_LIST) . ")))";
            } else {
                $sql .= " ON c.category_id=s.parent_category_id) ";            
            }
            $sql .= " WHERE c.category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")";
            $sql .= " ORDER BY c.category_order, c.category_name, c.category_id, s.category_order, s.category_name ";
        }
        $db->query($sql);
        if ($db->next_record()) {
            $category_number = 0;
            $is_subcategories = true;
            $shown_sub_categories = get_setting_value($vars, "categories_subs");
            $catalog_top_number = 0;
            $catalog_sub_number = 0;
            $column_width = intval(100 / $columns);
            $t->set_var("column_width", $column_width . "%");
            do {
                $category_number++;
                $catalog_sub_number++;
                $top_category_id = $db->f("top_category_id");
                $top_category_name = get_translation($db->f("top_category_name"));
                $top_a_title = get_translation($db->f("top_a_title"));
                $top_friendly_url = $db->f("top_friendly_url");
                $sub_category_id = $db->f("sub_category_id");
                $sub_category_name = get_translation($db->f("sub_category_name"));
                $sub_a_title = get_translation($db->f("sub_a_title"));
                $sub_friendly_url = $db->f("sub_friendly_url");
                if ($categories_image == 2) {
                    $category_image = $db->f("image");
                    $image_alt = get_translation($db->f("image_alt"));
                } else if ($categories_image == 3) {
                    $category_image = $db->f("image_large");
                    $image_alt = get_translation($db->f("image_large_alt"));
                } else {
                    $category_image = $image_tree_top;
                    $image_alt = get_translation($db->f("image_alt"));
                }
    
                $t->set_var("catalog_top_id", $top_category_id);
                $t->set_var("catalog_top_name", htmlspecialchars($top_category_name));
                $t->set_var("top_a_title", htmlspecialchars($top_a_title));
                if ($categories_type == 2){
                    $t->set_var("catalog_sub_id",  $sub_category_id);
                    $t->set_var("catalog_sub_name", htmlspecialchars($sub_category_name));
                    $t->set_var("sub_a_title", htmlspecialchars($sub_a_title));
                } else {
                     if (strlen($db->f("short_description"))) {
                        $t->set_var("short_description", get_translation($db->f("short_description")));
                        $t->parse("catalog_description", false);
                    } else {
                        $t->set_var("catalog_description", "");
                    }
                }
    
                $is_next_record = $db->next_record();
                $is_new_top = ($top_category_id != $db->f("top_category_id"));
    
                if ($categories_type == 2){
                    if (intval($shown_sub_categories) >= $catalog_sub_number || $shown_sub_categories == 0)
                    {
                        if ($sub_category_id && (!$allowed_sub_categories_ids || !in_array($sub_category_id, $allowed_sub_categories_ids))) {
                            $t->set_var("restricted_sub_class", " restrictedSubCategory");
                            $t->sparse("restricted_sub_image", false);
                        } else {
                            $t->set_var("restricted_sub_class", "");
                            $t->set_var("restricted_sub_image", "");
                        }
                        if ($friendly_urls && $sub_friendly_url) {
                            $list_url->remove_parameter("category_id");
                            $t->set_var("list_url", htmlspecialchars($list_url->get_url($sub_friendly_url. $friendly_extension)));
                        } else {
                            $list_url->add_parameter("category_id", CONSTANT, $sub_category_id);
                            $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
                        }
    
                        if ($category_id == $sub_category_id) {
                            $t->set_var("class_sub_selected", "selectedsubCategory");
                        } else {
                            $t->set_var("class_sub_selected", "subCategory");
                        }
                            
                        if ($is_next_record && !$is_new_top) {
                            $t->parse("catalog_sub_separator", false);
                        } else {
                            $t->set_var("catalog_sub_separator", "");
                        }
                        $t->parse("catalog_sub", true);
                    } elseif (($shown_sub_categories + 1) == $catalog_sub_number) {
                        if ($friendly_urls && $top_friendly_url) {
                            $list_url->remove_parameter("category_id");
                            $t->set_var("list_url", htmlspecialchars($list_url->get_url($top_friendly_url . $friendly_extension)));
                        } else {
                            $list_url->add_parameter("category_id", CONSTANT, $top_category_id);
                            $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
                        }
    
                        $t->parse("catalog_sub_more", false);
                    }
                }
    
                if ($is_new_top) {
                    $catalog_top_number++;
    
                    if ($friendly_urls && $top_friendly_url) {
                        $list_url->remove_parameter("category_id");
                        $t->set_var("list_url", htmlspecialchars($list_url->get_url($top_friendly_url . $friendly_extension)));
                    } else {
                        $list_url->add_parameter("category_id", CONSTANT, $top_category_id);
                        $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
                    }
    
                    if ($category_image)
                    {
                        if (preg_match("/^http\:\/\//", $category_image)) {
                            $image_size = "";
                        } else {
                            $image_size = @GetImageSize($category_image);
                            if (isset($restrict_categories_images) && $restrict_categories_images) {
                                $category_image = "image_show.php?category_id=".$top_category_id;
                            }
                        }
                        if (!strlen($image_alt)) { $image_alt = $top_category_name; }
                            $t->set_var("alt", htmlspecialchars($image_alt));
                            $t->set_var("src", htmlspecialchars($category_image));
                        if (is_array($image_size)) {
                            $t->set_var("width", "width=\"" . $image_size[0] . "\"");
                            $t->set_var("height", "height=\"" . $image_size[1] . "\"");
                        } else {
                            $t->set_var("width", "");
                            $t->set_var("height", "");
                        }
                        $t->parse("catalog_image", false);
                    } else {
                        $t->set_var("catalog_image", "");
                    }
    
                    if (!$allowed_categories_ids || !in_array($top_category_id, $allowed_categories_ids)) {
                        $t->set_var("restricted_class", " restrictedCategory");
                        $t->sparse("restricted_image", false);
                    } else {
                        $t->set_var("restricted_class", "");
                        $t->set_var("restricted_image", "");
                    }
                    
                    if ($category_id == $top_category_id) {
                        $t->set_var("class_top_selected", "selectedtopCategory");
                    } else {
                        $t->set_var("class_top_selected", "topCategory");
                    }                        
                        
                    $t->parse("catalog_top");
                    $t->set_var("catalog_sub", "");
                    $t->set_var("catalog_sub_more", "");
                    if ($catalog_top_number % $columns == 0) {
                        $t->parse("catalog_rows");
                        $t->set_var("catalog_top", "");
                    }
                    $catalog_sub_number = 0;
                }
    
            } while ($is_next_record);
    
            if ($catalog_top_number % $columns != 0) {
                $t->parse("catalog_rows");
            }
    
            $block_parsed = true;
            $t->parse("block_body", false);
        }
    } else if ($categories_type == 5) {
        // chained list type
        $is_ajax = get_param("is_ajax");
        $level = get_param("level");
        $pcategory = get_param("pcategory");
        if (!$pcategory) { $pcategory = 0; }

        $categories = array();

        $sql = " SELECT category_id, category_name FROM " . $table_prefix . "categories ";
        $sql .= " WHERE parent_category_id=" . $db->tosql($pcategory, INTEGER);
        $sql .= " ORDER BY category_order ";
        $db->query($sql);
        if ($db->next_record())    {
            do {
                $category_id = $db->f("category_id");
                $categories[$category_id] = get_translation($db->f("category_name"));
            } while ($db->next_record());
        }
        
        if ($is_ajax) {
            // json_encode for PHP4
            if (sizeof($categories) > 0) {
                echo "{";
                foreach($categories as $category_id => $category_name) {
                    echo '"' . $category_id . '":';
                    echo '"' . str_replace('"', '\\"', $category_name) . '",';
                }
                echo "}";
            }
            exit;
        } else {
        
            $html_template = get_setting_value($block, "html_template", "block_categories_chained_menu.html");
         $t->set_file("block_body", $html_template);
            $t->set_var("products_href", get_custom_friendly_url("products.php"));
        
            foreach($categories as $category_id => $category_name) {
                $t->set_var("category_id", $category_id);    
                $t->set_var("category_name", htmlspecialchars($category_name));
                $t->parse("category_option");
            }
 
            $block_parsed = true;
            $t->parse("block_body", false);
        }

    } else {// list type
        $html_template = get_setting_value($block, "html_template", "block_categories_list.html");
     $t->set_file("block_body", $html_template);
        $t->set_var("categories_rows", "");
        $t->set_var("categories",   "");

        $active_category_path = "0";
        $not = false;
        if ($categories_type == 4) { // Tree-type structure
            $sql = " SELECT category_path ";
            $sql .= " FROM " . $table_prefix . "categories ";
            $sql .= " WHERE category_id=" . $db->tosql($category_id, INTEGER);
            $db->query($sql);
            if ($db->next_record()) {
                $active_category_path = $db->f("category_path");
                $active_category_path .= $category_id;
            }
            $categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_PERM);
            $allowed_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_ITEMS_PERM);
        } else {
            $not = true;
            $categories_ids     = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_PERM);
            $allowed_categories_ids = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_ITEMS_PERM);
        }

        if (!$not && !$categories_ids) return;
        
        $categories = array();
        $sql = " SELECT category_id, category_name, a_title, friendly_url, ";
        $sql .= " short_description, image, image_alt, image_large, image_large_alt, parent_category_id ";        
        $sql .= " FROM " . $table_prefix . "categories ";
        if ($not) {
            if ($categories_ids) {
                $sql .= " WHERE category_id NOT IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") ";
            }
            $sql .= " ORDER BY parent_category_id, category_order, category_name ";
            $db->RecordsPerPage = 1000;
        } else {
            $sql .= " WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") ";
            $sql .= " ORDER BY category_order, category_name ";
        }
        $db->query($sql);
        while ($db->next_record()) {
            $cur_category_id = $db->f("category_id");
            $category_name = get_translation($db->f("category_name"));
            $a_title = get_translation($db->f("a_title"));
            $friendly_url = $db->f("friendly_url");
            $short_description = get_translation($db->f("short_description"));

            $image = $db->f("image");
            $image_alt = get_translation($db->f("image_alt"));
            $parent_category_id = $db->f("parent_category_id");
            $categories[$cur_category_id]["parent_id"] = $parent_category_id;
            $categories[$cur_category_id]["category_name"] = $category_name;
            $categories[$cur_category_id]["a_title"] = $a_title;
            $categories[$cur_category_id]["friendly_url"] = $friendly_url;
            $categories[$cur_category_id]["short_description"] = $short_description;
            $categories[$cur_category_id]["image"] = $image;
            $categories[$cur_category_id]["image_alt"] = $image_alt;
            $categories[$cur_category_id]["image_large"] = $db->f("image_large");
            $categories[$cur_category_id]["image_large_alt"] = get_translation($db->f("image_large_alt"));
            if ($not) {
                if ($allowed_categories_ids && in_array($cur_category_id, $allowed_categories_ids)) {
                    $categories[$cur_category_id]["allowed"] = false;
                } else {
                    $categories[$cur_category_id]["allowed"] = true;
                }
            } else {
                if (!$allowed_categories_ids || !in_array($cur_category_id, $allowed_categories_ids)) {
                    $categories[$cur_category_id]["allowed"] = false;
                } else {
                    $categories[$cur_category_id]["allowed"] = true;
                }
            }
            $categories[$parent_category_id]["subs"][] = $cur_category_id;
        }

        if (sizeof($categories) > 0 && isset($categories[0]))
        {
            $category_number = 0;
            $column_width = intval(100 / $columns);
            $t->set_var("column_width", $column_width . "%");

            set_categories(0, 0, $columns, 0, $categories_image);

            if ($category_number % $columns != 0) {
                $t->parse("categories_rows");
            }

            $block_parsed = true;
            $t->parse("block_body", false);
        }
    }


?>
  1. <?php
  2.     include_once("./includes/products_functions.php");
  3.     include_once("./messages/" . $language_code . "/cart_messages.php");
  4.     include_once("./messages/" . $language_code . "/reviews_messages.php");
  5.     include_once("./messages/" . $language_code . "/download_messages.php");
  6.     $user_id = get_session("session_user_id");        
  7.     $user_info = get_session("session_user_info");
  8.     $user_type_id = get_setting_value($user_info, "user_type_id", "");
  9.     $friendly_urls = get_setting_value($settings, "friendly_urls", 0);
  10.     $friendly_extension = get_setting_value($settings, "friendly_extension", "");
  11.     $columns = get_setting_value($vars, "categories_columns", 1);
  12.     $categories_type = get_setting_value($vars, "categories_type");
  13.     $category_id = get_param("category_id");
  14.     $search_category_id = get_param("search_category_id");
  15.     $search_string = get_param("search_string");
  16.     $is_search = strlen($search_string);
  17.     if ($is_search && $search_category_id) { $category_id = $search_category_id; }
  18.     $item_id = get_param("item_id");
  19.     if (!strlen($category_id)) {
  20.         if (strlen($item_id)) {
  21.             $category_id = get_db_value("SELECT category_id FROM " . $table_prefix . "items_categories where item_id=".$db->tosql($item_id, INTEGER));
  22.         } else {
  23.             $category_id = "0";
  24.         }
  25.     }
  26.     $category_id = intval($category_id);
  27.     
  28.     $t->set_var("products_href",  get_custom_friendly_url("products.php"));
  29.     $t->set_var("list_href",    get_custom_friendly_url("products.php"));
  30.     $t->set_var("details_href",   get_custom_friendly_url("product_details.php"));
  31.     $t->set_var("top_category_name",PRODUCTS_TITLE);
  32.     $t->set_var("category_rss", "");
  33.     $list_page = get_custom_friendly_url("products.php");
  34.     $list_url = new VA_URL($list_page);
  35.     $categories_image = get_setting_value($vars, "categories_image");
  36.     
  37.     if ($categories_type == 1 || $categories_type == 2) {
  38.         if (file_exists("images/".$settings["style_name"]."/category_image.gif")) {
  39.             $image_tree_top = "images/".$settings["style_name"]."/category_image.gif";
  40.         } else {
  41.             $image_tree_top = "images/category_image.gif";
  42.         }
  43.         $html_template = get_setting_value($block, "html_template", "block_categories_catalog.html");
  44.      $t->set_file("block_body", $html_template);
  45.         $t->set_var("catalog_sub",     "");
  46.         $t->set_var("catalog_sub_more",  "");
  47.         $t->set_var("catalog_rows",    "");
  48.         $t->set_var("catalog_top",     "");
  49.         $t->set_var("catalog_description", "");
  50.         $categories_ids = VA_Categories::find_all_ids("c.parent_category_id=" . $db->tosql($category_id, INTEGER), VIEW_CATEGORIES_PERM);
  51.         if (!$categories_ids) return;
  52.         $allowed_categories_ids = VA_Categories::find_all_ids("c.parent_category_id=" . $db->tosql($category_id, INTEGER), VIEW_CATEGORIES_ITEMS_PERM);
  53.                 
  54.         if ($categories_type == 2) {
  55.             $sub_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")", VIEW_CATEGORIES_PERM);
  56.             if (!$sub_categories_ids)
  57.                 $categories_type = 1;
  58.         }
  59.         if ($categories_type == 1) {
  60.             $sql = " SELECT category_id AS top_category_id, category_name AS top_category_name, a_title AS top_a_title, ";
  61.             $sql .= " short_description, friendly_url AS top_friendly_url, ";
  62.             $sql .= " image, image_alt, image_large, image_large_alt ";
  63.             $sql .= " FROM " . $table_prefix . "categories ";
  64.             $sql .= " WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")";    
  65.             $sql .= " ORDER BY category_order, category_name ";
  66.         } else {
  67.             // show categories as catalog
  68.             $allowed_sub_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")", VIEW_CATEGORIES_ITEMS_PERM);                        
  69.             $sql = " SELECT c.category_id AS top_category_id,c.category_name AS top_category_name, ";
  70.             $sql .= " c.friendly_url AS top_friendly_url, c.a_title AS top_a_title, ";
  71.             $sql .= " c.image, c.image_alt, c.image_large, c.image_large_alt, ";
  72.             $sql .= " s.category_id AS sub_category_id,s.category_name AS sub_category_name, ";
  73.             $sql .= " s.friendly_url AS sub_friendly_url, s.a_title AS sub_a_title ";
  74.             $sql .= " FROM (" . $table_prefix . "categories c ";
  75.             $sql .= " LEFT JOIN " . $table_prefix . "categories s ";            
  76.             if ($sub_categories_ids) {
  77.                 $sql .= " ON (c.category_id=s.parent_category_id ";            
  78.                 $sql .= " AND s.category_id IN (" . $db->tosql($sub_categories_ids, INTEGERS_LIST) . ")))";
  79.             } else {
  80.                 $sql .= " ON c.category_id=s.parent_category_id) ";            
  81.             }
  82.             $sql .= " WHERE c.category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ")";
  83.             $sql .= " ORDER BY c.category_order, c.category_name, c.category_id, s.category_order, s.category_name ";
  84.         }
  85.         $db->query($sql);
  86.         if ($db->next_record()) {
  87.             $category_number = 0;
  88.             $is_subcategories = true;
  89.             $shown_sub_categories = get_setting_value($vars, "categories_subs");
  90.             $catalog_top_number = 0;
  91.             $catalog_sub_number = 0;
  92.             $column_width = intval(100 / $columns);
  93.             $t->set_var("column_width", $column_width . "%");
  94.             do {
  95.                 $category_number++;
  96.                 $catalog_sub_number++;
  97.                 $top_category_id = $db->f("top_category_id");
  98.                 $top_category_name = get_translation($db->f("top_category_name"));
  99.                 $top_a_title = get_translation($db->f("top_a_title"));
  100.                 $top_friendly_url = $db->f("top_friendly_url");
  101.                 $sub_category_id = $db->f("sub_category_id");
  102.                 $sub_category_name = get_translation($db->f("sub_category_name"));
  103.                 $sub_a_title = get_translation($db->f("sub_a_title"));
  104.                 $sub_friendly_url = $db->f("sub_friendly_url");
  105.                 if ($categories_image == 2) {
  106.                     $category_image = $db->f("image");
  107.                     $image_alt = get_translation($db->f("image_alt"));
  108.                 } else if ($categories_image == 3) {
  109.                     $category_image = $db->f("image_large");
  110.                     $image_alt = get_translation($db->f("image_large_alt"));
  111.                 } else {
  112.                     $category_image = $image_tree_top;
  113.                     $image_alt = get_translation($db->f("image_alt"));
  114.                 }
  115.     
  116.                 $t->set_var("catalog_top_id", $top_category_id);
  117.                 $t->set_var("catalog_top_name", htmlspecialchars($top_category_name));
  118.                 $t->set_var("top_a_title", htmlspecialchars($top_a_title));
  119.                 if ($categories_type == 2){
  120.                     $t->set_var("catalog_sub_id",  $sub_category_id);
  121.                     $t->set_var("catalog_sub_name", htmlspecialchars($sub_category_name));
  122.                     $t->set_var("sub_a_title", htmlspecialchars($sub_a_title));
  123.                 } else {
  124.                      if (strlen($db->f("short_description"))) {
  125.                         $t->set_var("short_description", get_translation($db->f("short_description")));
  126.                         $t->parse("catalog_description", false);
  127.                     } else {
  128.                         $t->set_var("catalog_description", "");
  129.                     }
  130.                 }
  131.     
  132.                 $is_next_record = $db->next_record();
  133.                 $is_new_top = ($top_category_id != $db->f("top_category_id"));
  134.     
  135.                 if ($categories_type == 2){
  136.                     if (intval($shown_sub_categories) >= $catalog_sub_number || $shown_sub_categories == 0)
  137.                     {
  138.                         if ($sub_category_id && (!$allowed_sub_categories_ids || !in_array($sub_category_id, $allowed_sub_categories_ids))) {
  139.                             $t->set_var("restricted_sub_class", " restrictedSubCategory");
  140.                             $t->sparse("restricted_sub_image", false);
  141.                         } else {
  142.                             $t->set_var("restricted_sub_class", "");
  143.                             $t->set_var("restricted_sub_image", "");
  144.                         }
  145.                         if ($friendly_urls && $sub_friendly_url) {
  146.                             $list_url->remove_parameter("category_id");
  147.                             $t->set_var("list_url", htmlspecialchars($list_url->get_url($sub_friendly_url. $friendly_extension)));
  148.                         } else {
  149.                             $list_url->add_parameter("category_id", CONSTANT, $sub_category_id);
  150.                             $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
  151.                         }
  152.     
  153.                         if ($category_id == $sub_category_id) {
  154.                             $t->set_var("class_sub_selected", "selectedsubCategory");
  155.                         } else {
  156.                             $t->set_var("class_sub_selected", "subCategory");
  157.                         }
  158.                             
  159.                         if ($is_next_record && !$is_new_top) {
  160.                             $t->parse("catalog_sub_separator", false);
  161.                         } else {
  162.                             $t->set_var("catalog_sub_separator", "");
  163.                         }
  164.                         $t->parse("catalog_sub", true);
  165.                     } elseif (($shown_sub_categories + 1) == $catalog_sub_number) {
  166.                         if ($friendly_urls && $top_friendly_url) {
  167.                             $list_url->remove_parameter("category_id");
  168.                             $t->set_var("list_url", htmlspecialchars($list_url->get_url($top_friendly_url . $friendly_extension)));
  169.                         } else {
  170.                             $list_url->add_parameter("category_id", CONSTANT, $top_category_id);
  171.                             $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
  172.                         }
  173.     
  174.                         $t->parse("catalog_sub_more", false);
  175.                     }
  176.                 }
  177.     
  178.                 if ($is_new_top) {
  179.                     $catalog_top_number++;
  180.     
  181.                     if ($friendly_urls && $top_friendly_url) {
  182.                         $list_url->remove_parameter("category_id");
  183.                         $t->set_var("list_url", htmlspecialchars($list_url->get_url($top_friendly_url . $friendly_extension)));
  184.                     } else {
  185.                         $list_url->add_parameter("category_id", CONSTANT, $top_category_id);
  186.                         $t->set_var("list_url", htmlspecialchars($list_url->get_url($list_page)));
  187.                     }
  188.     
  189.                     if ($category_image)
  190.                     {
  191.                         if (preg_match("/^http\:\/\//", $category_image)) {
  192.                             $image_size = "";
  193.                         } else {
  194.                             $image_size = @GetImageSize($category_image);
  195.                             if (isset($restrict_categories_images) && $restrict_categories_images) {
  196.                                 $category_image = "image_show.php?category_id=".$top_category_id;
  197.                             }
  198.                         }
  199.                         if (!strlen($image_alt)) { $image_alt = $top_category_name; }
  200.                             $t->set_var("alt", htmlspecialchars($image_alt));
  201.                             $t->set_var("src", htmlspecialchars($category_image));
  202.                         if (is_array($image_size)) {
  203.                             $t->set_var("width", "width=\"" . $image_size[0] . "\"");
  204.                             $t->set_var("height", "height=\"" . $image_size[1] . "\"");
  205.                         } else {
  206.                             $t->set_var("width", "");
  207.                             $t->set_var("height", "");
  208.                         }
  209.                         $t->parse("catalog_image", false);
  210.                     } else {
  211.                         $t->set_var("catalog_image", "");
  212.                     }
  213.     
  214.                     if (!$allowed_categories_ids || !in_array($top_category_id, $allowed_categories_ids)) {
  215.                         $t->set_var("restricted_class", " restrictedCategory");
  216.                         $t->sparse("restricted_image", false);
  217.                     } else {
  218.                         $t->set_var("restricted_class", "");
  219.                         $t->set_var("restricted_image", "");
  220.                     }
  221.                     
  222.                     if ($category_id == $top_category_id) {
  223.                         $t->set_var("class_top_selected", "selectedtopCategory");
  224.                     } else {
  225.                         $t->set_var("class_top_selected", "topCategory");
  226.                     }                        
  227.                         
  228.                     $t->parse("catalog_top");
  229.                     $t->set_var("catalog_sub", "");
  230.                     $t->set_var("catalog_sub_more", "");
  231.                     if ($catalog_top_number % $columns == 0) {
  232.                         $t->parse("catalog_rows");
  233.                         $t->set_var("catalog_top", "");
  234.                     }
  235.                     $catalog_sub_number = 0;
  236.                 }
  237.     
  238.             } while ($is_next_record);
  239.     
  240.             if ($catalog_top_number % $columns != 0) {
  241.                 $t->parse("catalog_rows");
  242.             }
  243.     
  244.             $block_parsed = true;
  245.             $t->parse("block_body", false);
  246.         }
  247.     } else if ($categories_type == 5) {
  248.         // chained list type
  249.         $is_ajax = get_param("is_ajax");
  250.         $level = get_param("level");
  251.         $pcategory = get_param("pcategory");
  252.         if (!$pcategory) { $pcategory = 0; }
  253.         $categories = array();
  254.         $sql = " SELECT category_id, category_name FROM " . $table_prefix . "categories ";
  255.         $sql .= " WHERE parent_category_id=" . $db->tosql($pcategory, INTEGER);
  256.         $sql .= " ORDER BY category_order ";
  257.         $db->query($sql);
  258.         if ($db->next_record())    {
  259.             do {
  260.                 $category_id = $db->f("category_id");
  261.                 $categories[$category_id] = get_translation($db->f("category_name"));
  262.             } while ($db->next_record());
  263.         }
  264.         
  265.         if ($is_ajax) {
  266.             // json_encode for PHP4
  267.             if (sizeof($categories) > 0) {
  268.                 echo "{";
  269.                 foreach($categories as $category_id => $category_name) {
  270.                     echo '"' . $category_id . '":';
  271.                     echo '"' . str_replace('"', '\\"', $category_name) . '",';
  272.                 }
  273.                 echo "}";
  274.             }
  275.             exit;
  276.         } else {
  277.         
  278.             $html_template = get_setting_value($block, "html_template", "block_categories_chained_menu.html");
  279.          $t->set_file("block_body", $html_template);
  280.             $t->set_var("products_href", get_custom_friendly_url("products.php"));
  281.         
  282.             foreach($categories as $category_id => $category_name) {
  283.                 $t->set_var("category_id", $category_id);    
  284.                 $t->set_var("category_name", htmlspecialchars($category_name));
  285.                 $t->parse("category_option");
  286.             }
  287.  
  288.             $block_parsed = true;
  289.             $t->parse("block_body", false);
  290.         }
  291.     } else {// list type
  292.         $html_template = get_setting_value($block, "html_template", "block_categories_list.html");
  293.      $t->set_file("block_body", $html_template);
  294.         $t->set_var("categories_rows", "");
  295.         $t->set_var("categories",   "");
  296.         $active_category_path = "0";
  297.         $not = false;
  298.         if ($categories_type == 4) { // Tree-type structure
  299.             $sql = " SELECT category_path ";
  300.             $sql .= " FROM " . $table_prefix . "categories ";
  301.             $sql .= " WHERE category_id=" . $db->tosql($category_id, INTEGER);
  302.             $db->query($sql);
  303.             if ($db->next_record()) {
  304.                 $active_category_path = $db->f("category_path");
  305.                 $active_category_path .= $category_id;
  306.             }
  307.             $categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_PERM);
  308.             $allowed_categories_ids = VA_Categories::find_all_ids("c.parent_category_id IN (" . $db->tosql($active_category_path, INTEGERS_LIST) . ")", VIEW_CATEGORIES_ITEMS_PERM);
  309.         } else {
  310.             $not = true;
  311.             $categories_ids     = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_PERM);
  312.             $allowed_categories_ids = VA_Categories::find_all_ids(array('not' => 1), VIEW_CATEGORIES_ITEMS_PERM);
  313.         }
  314.         if (!$not && !$categories_ids) return;
  315.         
  316.         $categories = array();
  317.         $sql = " SELECT category_id, category_name, a_title, friendly_url, ";
  318.         $sql .= " short_description, image, image_alt, image_large, image_large_alt, parent_category_id ";        
  319.         $sql .= " FROM " . $table_prefix . "categories ";
  320.         if ($not) {
  321.             if ($categories_ids) {
  322.                 $sql .= " WHERE category_id NOT IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") ";
  323.             }
  324.             $sql .= " ORDER BY parent_category_id, category_order, category_name ";
  325.             $db->RecordsPerPage = 1000;
  326.         } else {
  327.             $sql .= " WHERE category_id IN (" . $db->tosql($categories_ids, INTEGERS_LIST) . ") ";
  328.             $sql .= " ORDER BY category_order, category_name ";
  329.         }
  330.         $db->query($sql);
  331.         while ($db->next_record()) {
  332.             $cur_category_id = $db->f("category_id");
  333.             $category_name = get_translation($db->f("category_name"));
  334.             $a_title = get_translation($db->f("a_title"));
  335.             $friendly_url = $db->f("friendly_url");
  336.             $short_description = get_translation($db->f("short_description"));
  337.             $image = $db->f("image");
  338.             $image_alt = get_translation($db->f("image_alt"));
  339.             $parent_category_id = $db->f("parent_category_id");
  340.             $categories[$cur_category_id]["parent_id"] = $parent_category_id;
  341.             $categories[$cur_category_id]["category_name"] = $category_name;
  342.             $categories[$cur_category_id]["a_title"] = $a_title;
  343.             $categories[$cur_category_id]["friendly_url"] = $friendly_url;
  344.             $categories[$cur_category_id]["short_description"] = $short_description;
  345.             $categories[$cur_category_id]["image"] = $image;
  346.             $categories[$cur_category_id]["image_alt"] = $image_alt;
  347.             $categories[$cur_category_id]["image_large"] = $db->f("image_large");
  348.             $categories[$cur_category_id]["image_large_alt"] = get_translation($db->f("image_large_alt"));
  349.             if ($not) {
  350.                 if ($allowed_categories_ids && in_array($cur_category_id, $allowed_categories_ids)) {
  351.                     $categories[$cur_category_id]["allowed"] = false;
  352.                 } else {
  353.                     $categories[$cur_category_id]["allowed"] = true;
  354.                 }
  355.             } else {
  356.                 if (!$allowed_categories_ids || !in_array($cur_category_id, $allowed_categories_ids)) {
  357.                     $categories[$cur_category_id]["allowed"] = false;
  358.                 } else {
  359.                     $categories[$cur_category_id]["allowed"] = true;
  360.                 }
  361.             }
  362.             $categories[$parent_category_id]["subs"][] = $cur_category_id;
  363.         }
  364.         if (sizeof($categories) > 0 && isset($categories[0]))
  365.         {
  366.             $category_number = 0;
  367.             $column_width = intval(100 / $columns);
  368.             $t->set_var("column_width", $column_width . "%");
  369.             set_categories(0, 0, $columns, 0, $categories_image);
  370.             if ($category_number % $columns != 0) {
  371.                 $t->parse("categories_rows");
  372.             }
  373.             $block_parsed = true;
  374.             $t->parse("block_body", false);
  375.         }
  376.     }
  377. ?>


Please let me know if this is not what you were referring to. Thanks.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9087
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Are the two above separate PHP pages? or everything that would be called on a single page load?

At first glance it is hard to tell as I do not think these are in any way creating 200 queries per page. They don't seem to be in any loops or anything. It is possible that a few of them could be combined still, but another optimization that could help would be to check the indexes on them to make sure that the lookups are quick.

Do you see any code that has SQL queries within some sort of while loop, or for loop on any of your pages? I am thinking that somewhere on your page you have some sort of loop with SQL queries inside that is really getting your SQL queries to jump to the high 200 range.
  • johnlynches
  • Novice
  • Novice
  • johnlynches
  • Posts: 15

Post 3+ Months Ago

They're not separate pages, but pieces of a page that loads. Each page that I have has many "sections" of these that must load. I don't see any loops in the pages, but then again I don't really know what a loop would look like if it slapped me in the face.

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.