Jump to content

budimir

Members
  • Content Count

    522
  • Joined

  • Last visited

Community Reputation

1 Neutral

About budimir

  • Rank
    Prolific Member
  • Birthday 09/25/1980

Profile Information

  • Gender
    Male
  • Location
    Croatia

Contact Methods

  • Skype
    budimir.skrtic
  1. Hey Barand! Thank you very much! That's it, exactly what I wanted!
  2. I'm trying to build a tree to display product groups, but I can't achieve what I want. There is a hierarchy for the tree which I need to follow: 1H 1HS 1HSMP I want to list all the categories (1H) with its subcategories(1HS), and it's subcategories (1HSMP). This is the code I'm currently using: <ul> <?php //Here we fetch category $categories_list = array(); if($stmt = $conn -> prepare("SELECT a.category, a.subcategory, a.subcategory1, a.category_description, a.subcategory_description, a.subcategory_description1, SUM(nsq.sales_amount) AS sales, SUM(nsq.sales_amount+nsq.cost_amount) AS RUC FROM dpb.articles a LEFT JOIN dpb.nav_sales_qty nsq ON nsq.article_no = a.article_no WHERE nsq.entry_type_desc = 'Prodaja' GROUP BY a.subcategory1")) { $stmt -> execute(); $stmt -> store_result(); $stmt -> bind_result($category, $subcategory, $subcategory1, $category_description, $subcategory_description, $subcategory_description1, $total_sales, $total_profit); while($stmt -> fetch()) { $categories_list[] = array('category' => $category, 'subcategory' => $subcategory, 'subcategory1' => $subcategory1, 'category_description' => $category_description, 'subcategory_description' => $subcategory_description, 'subcategory_description1' => $subcategory_description1, 'total_profit' => $total_profit, 'total_sales' => $total_sales); } $stmt -> close(); } foreach($categories_list as $key => $value) { ?> <li><?php echo $value['category'].' - '.$value['category_description']; ?> <ul> <?php //Here we filter subcategory if(strpos($value['subcategory'], $value['category']) === 0) { //Iterate over subcategory foreach ($value as $key2 => $value2) { debugVar($value2); ?> <li data-jstree='{"opened":true}'><?php echo $value2['subcategory'] . ' - ' . $value2['subcategory_description']; ?> <ul> <?php //Here we filter subcategory2 if (strpos($value['subcategory1'], $value['subcategory']) !== false) { ?> <li data-jstree='{"type":"file"}'> <?php echo $value['subcategory1']; ?> </li> <?php //Here we close subcategory1 if statement } ?> </ul> </li> <?php //Here we close subcategory if statement } } ?> </ul> </li> <?php //Close foreach loop } ?> </ul> The result I'm getting is attached in the photo, and it's not what I want! The result I need is the following: I find a category (1H), and then I find all of its subcategories which are 1H% (all that start with 1H) and display them bellow 1H. Then I iterate over all of these subcategories (example 1HS%, 1HP%, 1HRD%) and I find all of their subcategories which are starting with (1HS, 1HP, 1HRD) and display them. Example: 1H 1HS 1HSMP 1HSTR 1HSKT 1HP 1HPSD 1HPDD 1HPSA 1HRD 1HRDA 1HRDBV 1HRDTE 1HRDEF Can you please help me how to achieve that? I spent a lot of time, and I can't get the proper result.
  3. Thanks everyone for the help! @cloetensbrecht, Your answer pushed me to right direction. I had to change the conditions a bit, but it was your answer that gave me the idea. Thank you so much! I spent four days trying to figure it out! This is code that gives proper result: foreach ($cost_array as $key1 => $value1) { // group 1, group 2 and group 3 are empty and should stay => continue the foreach loop if (empty($value1['group1']) && empty($value1['group2']) && empty($value1['group3'])) continue; //When all three exist and are same it should continue if (!empty($form_group3) && $value1['group3'] == $form_group3 && !empty($form_group2) && $value1['group2'] == $form_group2 && !empty($form_group1) && $value1['group1'] == $form_group1) continue; if ($value1['group3'] != $form_group3 && !empty($form_group2) && $value1['group2'] == $form_group2 && !empty($form_group1) && $value1['group1'] == $form_group1) continue; if (!empty($form_group2) && $value1['group2'] == $form_group2 && !empty($form_group1) && $value1['group1'] == $form_group1) continue; if (!empty($form_group3) && !empty($form_group2) && !empty($form_group1) && $value1['group1'] == $form_group1) continue; //This covers situation where we have category and subcategory that match if (!empty($form_group2) && $value1['group2'] == $form_group2 && !empty($form_group1) && $value1['group1'] == $form_group1) continue; //This covers all situations where we have success only on category but nothing else if (!empty($form_group1) && $value1['group1'] == $form_group1 && empty($value1['group2']) && empty($value1['group3'])) continue; // otherwise unset the value unset($cost_array[$key1]); } I still need to catch one of the conditions, but that's what does the job. I'm sure it can be written in more elegant way. If there is any suggestions how to do it more elegant I would appreciate it.
  4. I'm trying to unset one record from array but I can't manage it, so I'm asking for someone to help me. Logic I'm trying to achieve is: User has an item with possible three categories, he posts a form and than I iterate over array and try to see if category3 matches, if not I go to category2, if not I go to category1. If I find one of the categories that matches array and category asked in form I proceed , but If I don't find any of the categories I unset that record in array.Below you will see an example what I've done now. I can't get the proper result. Either I unset all the records or unset the record that should stay. I'm trying different conditions for last three days without success. Record I'm talking about is with a key 5. This is my array: array (size=5) 0 => array (size=9) 'cost_no' => string 'D01' (length=3) 'cost_name' => string 'Carina' (length=6) 'cost_type' => string 'Customs' (length=7) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '5.00' (length=4) 'cost_id' => int 7 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 1 => array (size=9) 'cost_no' => string 'D02' (length=3) 'cost_name' => string 'Banka' (length=5) 'cost_type' => string 'Bank' (length=4) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '0.15' (length=4) 'cost_id' => int 8 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 2 => array (size=9) 'cost_no' => string 'D03' (length=3) 'cost_name' => string 'Špediter' (length=9) 'cost_type' => string 'Transport' (length=9) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '0.50' (length=4) 'cost_id' => int 9 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 3 => array (size=9) 'cost_no' => string 'D04' (length=3) 'cost_name' => string 'Troškovi firme' (length=15) 'cost_type' => string 'Tax' (length=3) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '21.00' (length=5) 'cost_id' => int 10 'group1' => string '' (length=3) 'group2' => string '' (length=3) 'group3' => string '' (length=3) 5 => array (size=9) 'cost_no' => string 'C1' (length=2) 'cost_name' => string 'Cost only for this group' (length=24) 'cost_type' => string 'Warehouse' (length=9) 'cost_measure' => string 'Percent' (length=7) 'cost_amount' => string '12.00' (length=5) 'cost_id' => int 12 'group1' => string 'ACC_P' (length=5) 'group2' => string '1401' (length=4) 'group3' => string '' (length=3) This is foreach and condition I tried to use to unset if non of the categories match ( it has to check from category3 to category 1). foreach ($cost_array as $key1 => $value1) { if (isset($form_group3) AND isset($value1['group3']) AND $value1['group3'] != $form_group3) { if (isset($form_group2) AND isset($value1['group2']) AND $value1['group2'] != $form_group2) { if (isset($form_group1) AND isset($value1['group1']) AND $value1['group1'] != $form_group1) { } else { unset($cost_array[$key1]); } } else { unset($cost_array[$key1]); } } else { unset($cost_array[$key1]); } } Groups user posts from form: $form_group1 = mysqli_real_escape_string($conn_mysqli, $_POST['group1']); $form_group2 = mysqli_real_escape_string($conn_mysqli, $_POST['group2']); $form_group3 = mysqli_real_escape_string($conn_mysqli, $_POST['group3']); The result I need to achieve is that all records where empty group3,group2,group1 have to stay and the one which has records in group3, group2 or group1 has to stay only if they match what user asks. So if form_group3 is same is array_group3, form_group2 is same as array_group2, form_group1 is same as array_group1 that record stays otherwise only that one is unset.
  5. Thank you for the help. I found a problem. Thank you very much.
  6. Hey Guru, Thanks for you're suggestion. This is error I get: Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Commands out of sync; you can't run this command now' in C:\wamp\www\pma\calculation\custom_based_method.php on line 159 What does that mean and how to trace it?
  7. Can someone explain why prepared statement in example below is failing while mysqli_query is working without any problem with exactly same set of data? I tried everything I could figure out and can't see the reason why it is happening. //Now we get costs in% and absolute $number = 0; $numberText = ""; $numberName = ""; $total_costs = 0; $total_costs_abs = 0; foreach($cost_array as $key => $value){ //Here we select only costs with % so we could calculate percentage if(strcmp($value["cost_measure"],"Percent") === 0){ //$number .= getPercentOfNumber($local,$value["cost_amount"])."<br>"; $number = getPercentOfNumber($local,$value["cost_amount"]); //$numberText.= $value["cost_amount"]." %<br>"; $numberText = $value["cost_amount"]; //$numberName .= "cost_name ".$value["cost_name"]."<br>"; $numberName = $value["cost_name"]; //Total value of all percentage costs $total_costs += $number; //Insert calculated costs in DB //Not working if ($stmt = $conn_mysqli -> prepare("INSERT INTO calculations_cost (calculation_id, costs_id, user_id, cost_time, original_number, cost_amount, cost_measure, calculated_cost, cost_name) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")) { $stmt -> bind_param("iiissssss", $calculation_id, $costs_id, $user_id, $create_time, $local, $numberText, $measure, $number, $numberName); $stmt -> execute(); $stmt -> close(); } //Working $sql = "INSERT INTO calculations_cost (calculation_id, costs_id, user_id, cost_time, original_number, cost_amount, cost_measure, calculated_cost, cost_name) VALUES ('$calculation_id', '$costs_id', '$user_id', '$create_time', '$local', '$numberText', '".$value['cost_measure']."', '$number', '$numberName')"; mysqli_query($mysqli,$sql) or die (mysqli_error($mysqli)); echo $sql."<br>"; //echo "Total costs: $total_costs<br>"; } }
  8. Thank you Psycho! You're code helped me to find my problem and get the value.
  9. I have tried that, but I can't get the value of select box.
  10. Hi, I have a radio button which, when clicked, is opening select. I would like to store the value of a radio and select into two separate cookies. This is my code I'm using, but I can't get second on change event to fire and get the value of select. I do get value of radio and store in cookie, but when trying to get value from select I get null. Can you, please help me and tell me what I'm doing wrong? Html code: <div class="row"> <div class="col-md-6"> <div class="radio clip-radio radio-primary"> <input type="radio" id="radio3" name="vertical" value="Pricelist" /> <label for="radio3"> Pricelist </label> </div> <div id="Pricelist" class="desc"> <div class="form-group"> <select class="cs-select cs-skin-elastic" name="pricelist" id="pricelist_select"> <option value="" disabled selected>Select pricelist</option> <option value="1">1</option> <option value="2">2</option> </select> </div> </div> jQuery //Displaying select box when type radio button is clicked $(document).ready(function() { $("input[name=vertical]").on( "change", function() { var test = $(this).val(); $(".desc").hide(); $("#"+test).show(); $("#pricelist_select").val(); $('#pricelist_select').trigger("change"); alert($("#pricelist_select").find(":selected").val()); $.cookie('pricelist_select', $("#pricelist_select").val()); } ); }); CSS .desc { display: none; }
  11. For some reason I can't get it to work. Could you give me an example how to get cookie value and display it to see the value?
  12. I'm using PHP to view cookie value, but obivously it's not working properly. <?php echo "$COOKIE['calc']"; ?> What javascript code would be to see cookie value in real time (without refreshing page)?
  13. Oh, OK. Now I can see that cookie immediatly gets new value, but the page is not displaying it when I go to second step. What do I need to do to get the value at the same moment when I get to second step?
  14. Yes, I can see it. It is created. It doesn't say any time when is created, but I can see it is created when radio is selected.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.