Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = new mysqli("localhost", "name", "password", "name"); //edw mpainoun ta stoixeia ths bashs
- /* ------------------------------ ΣΥΝΑΡΤΗΣΗ ΔΕΝΤΡΟΥ ΚΑΤΗΓΟΡΙΩΝ ------------------ΑΡΧΗ--------- */
- function dentrokathgorias ($proion_id, $glwssa_id) {
- global $conn;
- $kathgoria_step1 = $conn->query("SELECT id_category FROM ps_category_product WHERE id_product = ".$proion_id.";"); //id kathgoriwn me bash to id product
- $kathgoria_step1_array = array();
- $kathgoria_step2_array = array(); //einai to array mesa sto loop
- while($r1 = mysqli_fetch_assoc($kathgoria_step1)) {$kathgoria_step1_array[] = $r1;}
- $ki = 0;
- while($ki < count($kathgoria_step1_array)){
- $kathgoria_step2 = $conn->query("SELECT level_depth FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
- $vathos = $kathgoria_step2->fetch_object()->level_depth; //level kathgorias
- if ($vathos == 4){ //ektypwse to name ths giagias kathgorias + to name ths mamas + to name tou paidiou
- //id mamas
- $kathgoria_step3a = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
- $kathgoria_step3a_id = $kathgoria_step3a->fetch_object()->id_parent;
- //id giagias
- $kathgoria_step3b = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step3a_id.";");
- $kathgoria_step3b_id = $kathgoria_step3b->fetch_object()->id_parent;
- //onoma mamas
- $kathgoria_step4a = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3a_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
- $kathgoria_step4a_name = $kathgoria_step4a->fetch_object()->name;
- //onoma giagias
- $kathgoria_step4b = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3b_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
- $kathgoria_step4b_name = $kathgoria_step4b->fetch_object()->name;
- //onoma paidiou
- $kathgoria_step5first = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
- $kathgoria_step5first_name = $kathgoria_step5first->fetch_object()->name;
- //teliko apotelesma
- $kathgoriesdentro[] = $kathgoria_step4b_name.">".$kathgoria_step4a_name.">".$kathgoria_step5first_name;
- }
- elseif ($vathos == 3){ //ektypwse to name ths mamas kathgorias + to name tou paidiou
- //id mamas
- $kathgoria_step3 = $conn->query("SELECT id_parent FROM ps_category WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category'].";");
- $kathgoria_step3_id = $kathgoria_step3->fetch_object()->id_parent;
- //onoma mamas
- $kathgoria_step4 = $conn->query("SELECT ps_category_lang.name FROM ps_category_lang,ps_category WHERE ps_category_lang.id_category = ".$kathgoria_step3_id." AND ps_category_lang.id_lang = ".$glwssa_id.";");
- $kathgoria_step4_name = $kathgoria_step4->fetch_object()->name;
- //onoma paidiou
- $kathgoria_step5 = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
- $kathgoria_step5_name = $kathgoria_step5->fetch_object()->name;
- //teliko apotelesma
- $kathgoriesdentro[] = $kathgoria_step4_name.">".$kathgoria_step5_name;
- }
- else { //ektypwse thn monh kathgoria
- $kathgoria_step3else = $conn->query("SELECT name FROM ps_category_lang WHERE id_category = ".$kathgoria_step1_array[$ki]['id_category']." AND id_lang = ".$glwssa_id.";");
- $kathgoria_step3else_name = $kathgoria_step3else->fetch_object()->name;
- $kathgoriesdentro[] = $kathgoria_step3else_name;
- }
- $ki++;
- }
- echo str_replace(' |', '|', implode("|", $kathgoriesdentro));
- $kathgoriesdentro = array(); // adeiasma tou array dentrou
- }
- /* ------------------------------ ΣΥΝΑΡΤΗΣΗ ΔΕΝΤΡΟΥ ΚΑΤΗΓΟΡΙΩΝ ------------------ΤΕΛΟΣ--------- */
- dentrokathgorias(2411,8); //orismata: id proiontos , id glwssas (ellhnika = 8 , agglika = 1)
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement