Base de datos manejada Web Hosting Cuestiones

  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Abril 28th, 2011, 4:31 pm

Tengo un sitio web que es la base de datos mySQL impulsada (www_coinsupplyzone_com), pero es tan lento para cargar la mayor parte del tiempo. Algunas páginas tardan más de 30 segundos en cargarse, mientras que otras veces esa misma página se carga en menos de un segundo.

Actualmente estoy usando "inmotionhosting" como mi compañía de hosting. Hice mucha investigación antes de que apretó el gatillo en ellos, pero me preguntaba si no había tal cosa como una empresa de alojamiento que se especializa en sitios con base de datos? O si había una manera de ayudar a acelerar los tiempos de acceso a mi base de datos? Conozco a una buena cantidad de HTML y CSS, pero cuando se trata de bases de datos que soy un principiante.

Cualquier ayuda será apreciada, gracias....... Juan
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 28th, 2011, 4:31 pm

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Abril 28th, 2011, 5:52 pm

Es posible que desee preguntarle a su servicio de hosting si saben de alguna razón su página web se carga lento a veces. Podría haber muchas cosas que causan el problema, y ​​voy a enumerar algunas de ellas.

El primero podría ser su servicio de hosting tiene la culpa. Es posible que su servicio de hosting o bien tiene demasiados usuarios en sus servidores, que hace que se atascan a veces negativamente está afectando. También podría ser que su servicio de hosting no ha configurado su base de datos MySQL de forma óptima lo que podría hacer que se tienen malos resultados a veces.

El segundo podría ser que usted es culpable. ¿Va a crear sus propias consultas MySQL escribiendo el mismo código? O utilizar el software que ya ha sido escrito por otra persona? La razón que pido es porque si no hacerlo con cuidado artesanal las consultas SQL que fácilmente podría ejecutar algunas consultas resultados muy pobres que millones de la búsqueda de los registros que se tomaría un tiempo para ejecutarse. Si usted ha escrito su propio consultas SQL es posible que desee pasar por cada uno de ellos y ejecutarlos en phpMyAdmin o cualquiera que sea su método favorito es, y poner la palabra EXPLICAR frente a la consulta. Esto le puede decir todo tipo de cosas con el tipo de búsqueda utilizando la consulta es, para el número de registros es tener que buscar a través de darle los resultados. También puede indicar a usted si usted no ha configurado correctamente los índices que podrían velocidad de las consultas mucho. Así, por ejemplo si yo tuviera una consulta como esta que me da un resultado:

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


se puede encontrar información sobre él mediante la colocación de explicar la palabra en la parte delantera:

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


Su servicio de hosting puede trabajar con usted para ayudarle a diagnosticar su problema, o si no parece de mucha ayuda siempre se puede pasar a un servicio de hosting nuevo, como Ozzu gif "alt = =";)" título" Guiño ">

A pocos hilos a Ozzu que pueden ser útiles:

MySQL Límites

¿Cuáles son muchas consultas MySQL por página?

MySQL Tabla con millones de entradas
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Abril 28th, 2011, 6:50 pm

Me comuniqué con mi anfitrión en relación con este tema que siguen diciendo que lo más probable es un problema con mi internet y mi sitio carga muy bien en su extremo. Lo que no tiene sentido si es que durante el día las páginas tardan una eternidad en cargar, pero por la noche se carga en menos de un segundo o dos.

Yo hice lo siguiente en mi panel de control de hosting: "Comprimir los tipos MIME especificado" (text / html text / plain text / xml), pero eso es casi todo lo que sé hacer.

Yo no escribí el código de mí, es mi ViArt cesta de la compra que hizo por mí. Malos echa un vistazo a los otros hilos, gracias.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Abril 28th, 2011, 10:57 pm

Sólo por curiosidad, ¿tiene su página web recibe una gran cantidad de tráfico?

Normalmente los servidores web recibe más ocupados durante el día, pero si su sitio web no recibe una gran cantidad de tráfico, eso no significa que alguien más en su servidor no es que se bogging las cosas. Es realmente difícil de adivinar sin conseguir en su servidor y el diagnóstico de lo que está pasando, no puede haber numerosas razones que causan esto.

En cuanto a que sea la conexión local, que siempre es posible también. Digamos por ejemplo que haya una conexión de cable, es posible que durante el día en que unas pocas personas en su área local que está utilizando todo el ancho de banda disponible por lo tanto hacer que las cosas parecen más lentos para usted. Una vez más esto es sólo especulación, podría muy bien ser su anfitrión también. Una buena manera de comprobarlo, intente visitar algunos otros sitios web cuando su sitio aparece lenta y ver si la totalidad de Internet es lenta para ti, o simplemente su sitio web. Si es sólo su sitio web, entonces es muy probable que su proveedor de alojamiento web, o algo malo en su sitio web.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Abril 29th, 2011, 8:34 am

Mi sitio no obtiene más de 20 visitantes al día en este momento, por lo que debe ser la carga del servidor durante el día jugando conmigo.

Voy a ver si puedo crear páginas HTML estáticas con mi base de datos que pueden acelerar las cosas para mí. Sólo tengo demasiadas consultas corriendo por página.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Abril 29th, 2011, 5:15 pm

Tener demasiadas consultas corriendo por página realmente podría frenar una carga de la página hacia abajo. Muchas veces con sólo volver a hacer las consultas SQL y tratando de hacer las cosas más eficiente puede reducir el número está ejecutando por página. Por ejemplo, hace mucho tiempo Ozzu tenía alrededor de 30 llamadas SQL por página, y por hacer de nuevo todo y ser más inteligentes sobre cómo cada consulta se llamaba Recuerdo que fue capaz de bajar a alrededor del 10 por página, y todos de la misma la información fue recuperado todavía.

Puntos a tener en cuenta son los lazos que llamar a la misma pregunta una y otra vez. Así, por ejemplo, si había una serie de 10 valores de los que querían obtener resultados a través de SQL para cada valor, podría ejecutar un bucle y ejecutar 10 instrucciones SQL por separado, o puede ejecutar una sentencia SQL y la búsqueda de todos los identificadores dentro de esa declaración y los mismos resultados. Por lo general, la segunda forma es mucho más eficiente.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Abril 29th, 2011, 5:42 pm

Creo que eso es exactamente mi problema, mi programadores me dijo que mi sitio tiene hasta un par de cientos de preguntas por página. No sé si es posible para mí "un circuito" mi base de datos para acortar la consulta, ni siquiera por dónde empezar.

He hecho un ejemplo de la base de datos que utilizo para mi carrito de la compra en mi ftp:

www_coinsupplyzone_com / database_example.sql

Si uno de ustedes puede mirarlo y decirme si es posible "condensar" que estaría muy agradecida. Entonces puedo mirar en él en más detalles sobre la forma de acortar ojalá algunas de estas consultas.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Abril 30th, 2011, 9:55 am

Parte del problema podría ser la estructura de su base de datos, así que gracias por publicar esto. Sin embargo, por lo general el problema de la cantidad de consultas SQL se ejecuta no se debe a su base de datos en sí, sino cómo son las consultas de crear en el código de programación para acceder y recuperar los resultados de su base de datos. ¿Tiene un ejemplo de una parte del código que se ejecuta una de sus páginas lento que incluye algunas consultas SQL?
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Abril 30th, 2011, 3:02 pm

Aquí hay dos fragmentos de código de mi sitio. El primero es para llamar a la descripción de la categoría y el otro es para llamar a la lista de categorías:

Código: [ 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. ?>


Código: [ 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. ?>


Por favor, hágamelo saber si esto no es lo que se refiere. Gracias.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8925
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Online

Nota Mayo 1st, 2011, 6:22 pm

Si los dos anteriores por separado páginas PHP? o todo lo que se llamaría en una sola carga de la página?

A primera vista es difícil decir que no creo que se trata en modo alguno la creación de 200 consultas por página. Ellos no parecen estar en cualquier bucles ni nada. Es posible que algunos de ellos podían ser combinados todavía, pero otro de optimización que podría ayudar sería comprobar los índices de ellos para asegurarse de que las búsquedas son rápidas.

¿Ve usted algún código que ha consultas SQL dentro de una especie de bucle while o bucle en cualquiera de sus páginas? Pienso que en algún lugar en su página que tienen algún tipo de lazo con las consultas SQL dentro de que es realmente conseguir sus consultas SQL para saltar a la alta gama 200.
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • johnlynches
  • Novice
  • Novice
  • No Avatar
  • Registrado: Dic 20, 2010
  • Mensajes: 15
  • Status: Offline

Nota Mayo 2nd, 2011, 9:21 am

páginas Theyre no por separado, pero las piezas de una página que se carga. Cada página que tengo tiene muchos "secciones" de las que debe cargar. No veo que ninguna de bucles en las páginas, pero de nuevo no se sabe muy bien lo que es un bucle se vería como si me dio una bofetada en la cara.

Publicar Información

  • Total de mensajes en este tema: 11 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 32 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC