Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. i was going with - ... BETWEEN startdate AND IFNULL(enddate,'9999-12-31')
  2. didn't see this thread before. the 'correct' way of doing this is to store the pricing information in a table using the productId, the start date (or datetime) and the end (or a NULL) date (or datetime.) each time the price changes for an item, you would set the end date (or datetime) for the previous price and insert a new row with the start date (or datetime) and the new price. any query to calculate the price would use the date (or datetime) of the quote to match the correct pricing information. any chance that your thread about the switch/case statement taking a long time is doing a ton of database queries (in a loop) that could account for the bad performance?
  3. is this shared web hosting, where there are a number of accounts running on the same server and you are using the default/shared location for your session data files?
  4. the code you posted above is only calling other code that's actually doing the work. without the relevant code, we cannot possibly tell you anything about why it isn't working or even what to look at next to find out more about what's going on.
  5. about the only way you would get that error is if you hadn't saved the contents of the pet.php file at the time you ran the pettest.php code, i.e. pet.php exists, but it is empty.
  6. ^^^ you are probably fetching one row before the start of your loop or you sql query is wrong. ^^^ the code you showed us is fetching the database rows into $e, not $d. $d must be some other variable from before the start of this code. if you are running the query/code you posted in this thread inside of a loop, you shouldn't. you should form and run ONE JOINed query that gets all the related data at one time.
  7. i would say yes. i have done a lot of BOMs/estimating for industrial controls, at the $1.5M level for entire plants. you are building a bill of materials (somewhere). that bom needs the quantity of each direct item that has been added, and any follow-on/sub-items that are the result of each item, recursively down to the end of the chain. from a processing point of view, just do things once, when an input is added/deleted/changed, and only for those things that are in the bom. this approach would be the same as an onchange event in a browser or a trigger in a database. some input event occurs, the code that runs, takes the rules that have been defined for that event and applies them as needed. if a window gets added/deleted, the rules defined for that window type tell the code what and what quantity of sub-items (such as the corner molding) need to be added/deleted from the bom, any of those sub-items will have rules that tell the code what and what quantity of sub-sub-items (such as fasteners) need to be added/deleted from the bom. the array structure you have for the overallQuantities already has an array of arrays for each productId, though it looks like the code isn't using more than the first element of each array. the suggested usage of the [main_item_id] as the secondary array index, in reply #6, keeps each element in the array tied to what caused that quantity. if you change the quantity of the parent (delete a specific size window), you only have to calculate and update that corresponding one element for the child item (corner molding.) all the other quantities of that particular child item aren't touched. because you have more than just two levels, what i posted in reply #6 would actually be recursive, and look like the following with as many levels as needed - overallQuantities[main_item_id] = quantity overallQuantities[sub_item_id][main_item_id] = quantity overallQuantities[sub_sub_item_id][sub_item_id][main_item_id] = quantity for the insulated vs uninsulated pricing, i would maintain two boms, one for each case. the code would calculate quantities with and without insulation and store the results in separate boms (actually, i would just use an array with a main index that indicates insulated and uninsulated branches.) for the _calc() function in my example. you can make as many different functions that you need for the different classes of rules. just call the correct one depending on the situation. in the list of rules, you can 'dynamically' call you own functions, using variable functions, by listing the function name somewhere in the rules. in my example, i am calling the ceil function using variable functions. your rule(s) could have function name, like i used, or even an array of function names that you loop over to dynamically call each function in turn.
  8. yes, it is. and, yes, it is. it's testing the result of the assignment statement, which will be the value that was assigned. when there are no more rows, the fetch statement returns a false, which will be assigned to the $x variable, and the value tested for the loop condition will be a false and the loop will end. from the documentation for the assignment operator -
  9. we understand what you are doing and how you are doing it. the problem is, your current code is taking a long time to run and all the hard-coded logic and hard-code properties in the code are a maintenance problem. from what i gather, to recalculate the bom/price, upon each change being input, you are currently calling the code for every possible building productId (~300 times), to get each id to calculate how much of it is needed based on the quantity of what it is used for. this also requires that you call the code with the product id's in the proper order. for example, if you haven't called the code to update the cornerMoulding quantity yet, any product id that is used for cornerMoulding, such as fasteners, won't produce the correct quantity. this is what i would call a bottom-up approach. my suggestion earlier in the thread is a top-down approach, where each change only causes the items affected by that change to be recalculated. for the performance problem, if the function method produced acceptable performance, you would want to continue using that method. for the code maintenance problem (top-down or bottom-up approach), you need a data driven design, where you define the rules in a data structure (an array for now, a database table later) that tells the code what to do. for the information you have shown in this thread (bottom-up approach), the following pseudo/non-functional code demonstrates a data driven design - // define the rules that tell the code what to do $items = array(); $items[] = array(threeByThreeFixedWindow,1.5); // id, individual multiplier $items[] = array(fourByThreeFixedWindow,1.5); // id, individual multiplier $items[] = array(threeFootStandardDoor,2.5); // id, individual multiplier $rules[cornerMoulding] = array($items,1,'ceil'); // array of item(s), group multiplier, operator $items = array(); $items[] = array(smokeStop,1); // id, individual multiplier $items[] = array(fireStop,1); // id, individual multiplier $rules[smokeDamper] = array($items, 3,'ceil'); // array of item(s), group multiplier, operator $items = array(); $items[] = array(poly,1); // id, individual multiplier $rules[tuckTape] = array($items, 1/2000, 'ceil'); // array of item(s), group multiplier, operator // a function that knows how to apply the rules function _calc($rule){ $qty = 0; foreach($rule[0] as $item){ $qty += $this->getTotalQuantityBuildingProduct($item[0], $showInsulation, $showPerma) * $item[1]; // get the total for the productId and apply the individual multiplier } $qty *= $rule[1]; // apply group multiplier if($rule[2] == ''){ return $qty; } else { return $rule[2]($qty); // use variable functions to apply the operator } } // example usage - $quantities[] = _calc($rules[smokeDamper]); // call this to use the defined $rules for the productId, instead of the hard-code program logic
  10. your code that's not commented out, that's using the $data values, is after the end of the while(){} loop. at that point, $data is a FALSE value. there is no $data[0], ... for the code to use. you should be getting 'undefined offset...' php error messages. also, the code inside your while(){} loop is never incrementing $row, so the code inside the loop, will skip every row.
  11. and again - just posting that you cannot get something to work is pointless, because we are not going to write or fix your code for you. also, the link i posted above in this thread HIGHLIGHTS the http_build_query() statements in the code, you cannot miss where they are being used at in the code.
  12. i've been looking at your code posted in this thread, and it appears that the rules in the code are for calculating the amount of a sub-item by getting the quantity of each relevant main item that uses that sub-item and putting that quantity through the rule in this code. also, despite storing the quantity for each productId as an array within the main array, the code in this thread is only storing ONE array element, with the total quantity. this means you are calling the getQuantityBuildingProduct() function for each sub-item that a main item uses, each time the main item quantity gets changed (unless you are calling the function for EVERY POSSIBLE sub-item, every time ANY main item quantity changes, in which case i can see why this would take 10 seconds). this requires that the code (or data) for each main item contain a list of sub-items and your code in this thread requires the correct rule for each sub-item. so, you have two separate places in the code that must be kept up to date with any new or changed relationship between main and sub-items. i suggest, instead, just using the list of sub-items, located in the main item code (or data), to call the appropriate rule for each sub-item and update the sub-item quantity at the time you update a main item quantity. you are storing data like this - overallQuantities[main_item_id][] = quantity // main items overallQuantities[sub_item_id][] = quantity // sub items if you add the main_item_id as an array index for the sub-items, you can find and update the corresponding quantity of a sub-item when the quantity of the main item changes - overallQuantities[sub_item_id][main_item_id] = quantity for example - overallQuantities[cornerMoulding][threeByThreeFixedWindow] = x quantity overallQuantities[cornerMoulding][threeFootStandardDoor] = y quantity your getTotalQuantityBuildingProduct() function will work with this structure (it's actually getting a single element array now, but would be getting an array of arrays, if a sub-item is used with more than one main item.) you can also replace the foreach() loop in the getTotalQuantityBuildingProduct() function with an array_sum() call, both with your current scheme and with the one i have suggested. this will also allow you to produce a cross-reference listing of the sub-items showing what amount of them are used for each different main item - cornerMoulding - threeByThreeFixedWindow - x quantity threeFootStandardDoor - y quantity edit: and in thinking about your use of the $this->overallQuantities[$productId] array to cache the amounts, if you change a quantity of a main item, i.e. the number of a type of window, your code won't recalculate the amount of a sub-item, i.e. the corner molding, if the sub-item amount is already in the array, which it likely would be, unless you have even more code that we haven't seen to take care of this common occrance.
  13. you would need to check the mail server's logs to find out what is actually happening. it is either deciding not to send them (usually due to relaying restrictions combined with what the to: and from: email addresses are) or the receiving mail server is refusing them or deciding not to process them (if they are invalid or the receiving mail server cannot confirm that your mail server is authorized to send email from where the mails stay they are from), or the receiving mail server is considering them spam/junk and is placing them into the junk mail folder of the recipient. if the mail server is returning an error to php, the mail() function should returning a false value that you can test for. if the mail server is returning error information to php, you can either echo or log the php errors to find out more information. are you sending an email to yourself, i.e. a mail box at your mail server or are you trying to send the emails through your mail server to other/external mail servers? also, in the cases where it doesn't work, what sort of error or symptom are you getting?
  14. what was the performance of your code when using functions (i'll assume you were calling the appropriate function dynamically using variable functions?)? using a class->property as the case x: value, is not going to be as efficient as using a fixed value. i would use a defined constant as the case values. the same would be true for all the other class->properties you are showing in the code. you have essentially created a different variable/property, who's name indicates the purpose of the variable, when in fact nothing about the usage is variable.
  15. the problem seems to be because the ?msg=x that you are putting into your links are only putting an x value from the original message, not the replies.
  16. your raiz/root column only has to do with displaying a list of the original message and the replies that belong with that message. it doesn't have anything to do with displaying a specific message or marking a message as being read. displaying a specific message or marking a message as being read only involves the id of that specific message. the only people who can view any specific message are the sender or the recipient. your first query should enforce that condition - $result = mysqli_query($con, "SELECT * FROM message WHERE id = $message AND (`to` = $utilizador OR `from` = $utilizador)"); the update query, which in your last post above didn't correct the php logic to use a == comparison, should be - if($utilizador == $ln['to']){ $update= "UPDATE messages SET `read` = 1 WHERE id = $message"; mysqli_query($con, $update); } note: read is a reserved mysql keyword (along with from and to in the first query) and must be enclosed in back-ticks `` to prevent mysql errors. you would be getting a mysql error from your update query. your code needs to ALWAYS have error checking logic in it, to get your code to tell you when, where, and why something is failing. lastly, the $_GET['msg']/$message are external data and can be anything. you MUST validate that they are of the expected format and you must protect against sql injection. the best way of protecting against sql injection is to use prepared queries. for what you are using the value for in your code, someone could inject sql that allows them to display ANY message that belongs to anyone. which defeats the point of a Private Message system.
  17. the following forum post addresses much of what you should be doing in your code - http://forums.phpfreaks.com/topic/296742-hello-pretty-simple-php-form-i-broke-itplease-assist/?hl=%2Bsending&do=findComment&comment=1513725 pay particular attention to item #8 (the smiley) about the From: email header. edit: i also notice that you have $POST used in some of your code. it's $_POST. if you had php's error_reporting set to E_ALL and display_errors set to ON, you would be getting undefined error messages alerting you to the incorrect variable names.
  18. if your free web host doesn't provide sending/outgoing email, then the person you know that is able to send/receive contact form emails is likely sending the email through or just to some other mail server, such as a gmail account. if your web host hasn't blocked communications on port 25, you can, using a script like phpmailer, send emails to your own personal email account, hosted somewhere else. to do this, you must use smtp authentication (supplying your email account's email address and password) with the phpmailer script. there are examples at the phpmailer site.
  19. you need a user/permission system. see the following basic example - // roles define('BUYER',0); define('SELLER',1); // other roles would go here... // permissions define('CREATE_LISTING',1); define('POST_REPLY',2); // other permissions would go here.... class user { private $permissions = array(); public function __construct($user_id){ // this code retrieves the user's permissions based on their assigned role // define permissions to roles. this would normally be in a database table // for demo purposes, these are just assigned here... $permissions[BUYER][] = POST_REPLY; $permissions[SELLER][] = CREATE_LISTING; $permissions[SELLER][] = POST_REPLY; // fake code to assign a role based on dummy user id's // actual code would retrieve the role from wherever it is stored if($user_id == 123){ // a dummy buyer $role = BUYER; } if($user_id == 456){ // a dummy seller $role = SELLER; } $this->permissions = $permissions[$role]; // store this user's permissions } public function has_permission($var) { return in_array($var,$this->permissions); } } $_SESSION['USERID'] = 123; // a fake user - with role of buyer // example usage - $user = new user($_SESSION['USERID']); // get this user's permissions if($user->has_permission(CREATE_LISTING)){ // code for creating or processing a listing... echo 'you can create a listing'; } if(!$user->has_permission(CREATE_LISTING)){ // note the ! (not) echo 'you cannot access this page'; } if($user->has_permission(POST_REPLY)){ echo 'you can post a reply'; }
  20. what you are currently doing, lets the player attack other people by clicking on a link. if they change the value in the url and can accomplish the same thing as clicking on one of the other links, what difference does it make? what specifically about being able to submit a value in the url to attack other people vs clicking on a link to attack other people is a problem? edit: submitting data that changes something on the server should be handled using a post method form. url get parameters should control what is displayed, i.e. gotten, on the page. this won't prevent someone from submitting any value they want, because anyone can submit any data via post or get that they want.
  21. we cannot help you with what you tried unless you post what you tried. your task is simple, change each place that is producing a pagination link, of which there are several, so writing a user function may be helpful, so that it also has the id=value in the link. the method i suggested makes this general purpose and future proof. it also url-encodes the values for you in case they have any characters that are not allowed in links. the code in the linked to forum reply shows how to do this.
  22. each different form processing code needs to test for a unique field name in the form, such as a hidden field, so that only the form processing code that corresponds to the submitted form will run. // post method form processing code if($_SERVER['REQUEST_METHOD'] == 'POST'){ if(isset($_POST['a_field_that_uniquely_identifies_form_1'])){ // all the form processing code for form 1 } if(isset($_POST['a_field_that_uniquely_identifies_form_2'])){ // all the form processing code for form 2 } // any other form processing code // if there are no errors, you should do a header() redirect to the exact same url of this page so that the browser won't try to resubmit the form data // to pass any 'success'/'thank you' message to be displayed when the page gets displayed after this redirect, pass it/them in $_SESSION variables // you should also exit;/die; after any header redirect to prevent the remainder of the code on the page from running // if there are errors, don't redirect and let the code on this page display the error messages and redisplay the form } // end of post method form processing code // any get request - display code starts here... the above code should set error messages in an array - $errors['form1_name'][] = 'some message'; or $errors['form2_name'][] = 'some message'; at any point to detect if there are errors, you can just test if the $errors array is empty or not. to display the errors for any form, just test for and loop over the $errors['form1_name'] array elements.
  23. your pagination links need to include the $_GET['id'] value (and any future possible items you add to links.) if you build the query string part of the pagination links using http_build_query(), this will happen 'automatically'. if you do an advanced search on the forum for http_build_query() and my user name, you will find a page worth of examples showing how to use http_build_query() to combine any existing $_GET variables with your pagination values when you build the links. edit: here's one showing the phpfreaks pagination script, modified to use http_build_query() - http://forums.phpfreaks.com/topic/291074-php-mysli-pagination-with-items-per-page-select-option/?hl=%2Bhttp_build_query&do=findComment&comment=1491152
  24. Lines 120-125 are probably inside of a conditional statement, so that they don't become defined until that conditional statement is true. function definitions should all be grouped together and come near the start of your code or even be in a separate file that gets included near the start of your code.
  25. the WHERE clause would be - WHERE YEAR(LastVisit) = whatever_year_value_you_want i'm pretty sure this would have the same level of performance as your Last 6 months query.
×
×
  • 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.