Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,356
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. your form doesn't have any field named 'id', so, $_POST['id'] doesn't exist. this would be throwing php errors if you had php's error_reporting set to E_ALL and display_errors set to ON (preferably in the php.ini on your development system.) with no id value, the WHERE clause in the query is false, so the affected rows will always be zero.
  2. yes, but have you been looking at what your code is doing? you have added a completely separate sql query for the company name, instead of modifying the existing sql query so that it would match the data you want. in programming (and for any goal), you must define what you want the code to do, before you can write any code to do it. otherwise, you can end up spending an infinite amount of time working on something without accomplishing anything useful. just ask the programmer's who wrote this forum software. so, first define what you want to the WHERE clause in the sql query to be for the four possibilities of date range and company name selection - 1) no date range (empty date form fields) and no company name (the ALL default choice) - you want the query to match all data, i.e. a query with a WHERE clause without any terms in it for the date and company name. if these are the only things being used in the WHERE clause, you can leave the entire WHERE clause out of the query. 2) a date range and no company name - you want the query to match data - WHERE sl_iv.DOCDATE BETWEEN 'the_start_date' AND 'the_end_date' 3) no date range and a company name - you want the query to match data - WHERE COMPANYNAME = 'the_selected_company_name' 4) both a date range and a company name - you probably want the query to match data with both conditions - WHERE sl_iv.DOCDATE BETWEEN 'the_start_date' AND 'the_end_date' AND COMPANYNAME = 'the_selected_company_name' given that the original code has this - $queryCondition = "";, your task would be to build the correct WHERE clause in that variable, it's already being put into the sql query statement. a general purpose way of doing this, that will support any number of different terms/filters, is to add each term as an element to an array. you can then just implode() the array using the " AND " keyword to produce a WHERE clause containing all of the terms. this will work regardless of the number of terms you add to the array (provided you define an empty array first.) you also need to do something that i suggested at the top of this thread and use a get method form. you would also want to re-populate the form fields with any previous selection so that the form is 'sticky' and retains the values and you need to display the data from the query someplace beside inside the search form. lastly, you need to protect against sql special characters in the data from breaking the sql syntax (which is how sql injection is done) and causing errors. the best way of doing this is to use a prepared query with place-holders in the sql statement for data values, then supply the data when the query is executed. unfortunately, doing this for a dynamic sql statement, which what you have with different possible filters, isn't very straight-forward using the php mysqli extension. the php PDO extension is an all around better choice to use over the mysqli extension and you should switch to it if you can.
  3. what do you mean, 'you hope.' that's why you test code, to confirm if it produces the correct result. that would tell you if the code is correct or if you must go back and find what it is doing wrong.
  4. change this - $ques[] = $row['q_text']; to this - $ques[$row['question_id']] = $row['q_text'];
  5. when the submitted value is the ALL choice, you would leave the corresponding term out of the WHERE clause.
  6. it's not entirely clear, since there's no context or explanation in the attached spread-sheet, what the data is and which of it is even relevant. i'll venture some guesses - 1) The data is the result set/rows from an sql query? if so, if you store that data into an array in your code and use var_export() on that array, you can paste valid php code that we could use as test data. 2) Expr2 is the user/employee id and the Expr3 is the text answer you want to display? if so, here's a way of producing the output - 1) query for and retrieve the question id and question text, in the order that you want to display them (in case they are not to be displayed by the id ordering), separately from the main data retrieval query. store the question id/text into an array, using the question_id as the array index and the question text as the array value. you would leave out the question text in the main data retrieval query. 2) when you retrieve the main data, loop over it and pre-process/pivot it and store it into a multi-dimensional array. the first array dimension/index would be the employee_id. the second array dimension/index would be question_id - $data[employee_id][question_id][] = 'text answer to display'; // the last [] is to accommodate multiple replies to any question. 3) to produce the output, produce the table header by outputting the first column, then loop over the array from item #1 above. to produce the data section, loop over the pre-processed data. this will give you the employee_id and the array of replies for that employee id, with the reply array index being the question_id. loop over the array question id's, from item #1, to get the question_id's in the order that you are displaying the questions/replies. use the question_id to reference the correct reply for the current employee id. this will give you an array of replies for that question_id. loop over or implode() this array to output the text in each table cell. see the following simplified example - // some made up questions $q = array(); $q[1] = 'q1'; $q['2A'] = 'q2 a'; $q['2B'] = 'q2 b'; $q[3] = 'q3'; $q[4] = 'q4 mult'; // some made up data $data = array(); $data[1][1][] = 'e1 q1'; $data[1]['2A'][] = 'e1 q2 a'; $data[1]['2B'][] = 'e1 q2 b'; $data[1][3][] = 'e1 q3'; $data[1][4][] = 'e1 q4 1'; $data[1][4][] = 'e1 q4 2'; $data[2][1][] = 'e2 q1'; $data[2]['2A'][] = 'e2 q2 a'; $data[2]['2B'][] = 'e2 q2 b'; $data[2][3][] = 'e2 q3'; $data[2][4][] = 'e2 q4 1'; $data[2][4][] = 'e2 q4 2'; // produce table header echo "<table>\n"; echo "<tr><th>Employee ID</th>"; // loop over array of questions for the header foreach($q as $question) { echo "<th>$question</th>"; } echo "</tr>\n"; // produce table data foreach($data as $employee_id=>$replies) { // $replies is an array with the question_id as the array index echo "<tr><td>$employee_id</td>"; // loop over the question id's in the order they are being displayed foreach(array_keys($q) as $q_id) { // is there a reply for this quesiton_id if(isset($replies[$q_id])) { // there is a reply for this question // there can be multiple replies to a question - separate them with a <hr> in the table cell echo "<td>"; echo implode('<hr>',$replies[$q_id]); // note: this works correctly if there is a single reply, the result is just the single array element by itself echo "</td>"; } else { // no reply, output whatever you want for this case echo "<td>n/a</td>"; } } echo "</tr>\n"; } echo "</table>\n";
  7. we can only help you with problems in your code when you post your code. post your attempt with both filters in it. btw - you should be using a method='get' form for controlling what will be displaying on the page.
  8. you would need to add some php code to actually use the data from the COMPANYNAME select/option menu to add the correct term to the WHERE clause in the sql query statement. there's nothing in the code now.
  9. return, the point where the sql syntax error is occurring at is a reserved mysql (database server) keyword. are you sure the original query wasn't as follows, with back-ticks around the table name - "SELECT * FROM `return` WHERE nMemberID='$nMemberID' AND nInfoID='$nInfoID' ORDER BY nReturnID DESC"; next, just converting the mysql_ statements to mysqli equivalents is not enough. you must also safely supply data values to the sql query statement. if $nMemberID or $nInfoID are coming from external data or they could contain any sql special characters, they must either be properly escaped (see the mysqli real escape string function/method) or you need to use a prepared query with place-holders in the sql statement for the data values and then bind the actual data to the place-holders. a prepared query is actually the best choice since it is impossible for injected sql in the data to be treated as sql syntax, whereas using the escape string function must have the proper character encoding set for the database connection to match what the database tables are set up for.
  10. if you are just learning, start with one or two form fields and get the code to work so that you are learning and understanding how the code works. if you are doing this for real and you have more than about three form fields, you should NOT write out lines of code for each possible form field. you would instead dynamically process the form data, by defining the expected fields in a data structure (array or database table.) you would then loop over the defining data structure and dynamically reference the data, to first validate it, then dynamically produce the email message body, all without writing out line after line of code that only differs in the form field it corresponds to. next, any data you put into the email message body needs to be passed through htmlentities() so that any html/javascript/css in the submitted data won't be operated on by the receiving email client. any data you put into the email header must be validated that it is exactly and only an expected value. lastly, the email is not being sent FROM the email address that someone entered in the form. the email is being sent from the mail server at your web host. the From: email address should be a valid email address at your web host, so that the From: email address corresponds to the sending mail server and so that bounce messages from the receiving mail server have a place to go to.
  11. your loop is also looping forever (until the php time limit is reached), since the condition being tested by the loop is a fixed value. you don't even need a loop for what you are doing. your sql query should be trying to match one row, based on the username. if the username/one row is found, you would fetch that one row, then verify if the hashed version of the entered password matches the hashed password from when the user registered. see php's password_hash() and password_verify() functions for this.
  12. look at your code, between where you are executing the sql query and where you are looping over the data from that query.
  13. is the query failing (from error handling logic that you should always have in your code) or are the php statements failing (form having php's error_reporting/display_errors turned fully on in the php.ini on your development system)? if your original posted code was using the php mysqli extension, why are you now using the php mysql extension? the mysql extension has been removed from the php since the end of last year. you should also be using a prepared query (supported by the php mysqli and pdo extensions) to supply the data values to the sql query statement and this will also make executing the query inside of a loop slightly more efficient, since you will prepare the query only once before the start of the loop. also, if you are still asking questions in this thread, you should de-select the solved post so that people will see that the thread is not actually solved and will read it to see the new questions.
  14. what debugging have you done to find what the code IS doing? the code i posted is tested and submits and logs the data. aside from the note about the actual database statements not being used and therefore not being tested, the code works. is your data being being displayed? does your database table have an id column, that's named 'id'? what does the developer console in your browser show? is the 'log.txt' file being created on the server?
  15. so, i went through your code to figure out what it is doing, in order (pun intended) to figure out how to make this work. starting with your html markup - 1) the id='...' attribute you have for the column div's, should start with a letter, to make them valid. i choose to use id='COL_n', where n = 1, 2, ..., 6 2) the portlet div's needs an id attribute so that the serialize/toArray functions have something to use as data. i choose to use id='ID_n', where n is the job id auto-increment column value from your database table (if you don't have a job id, you need one.) 3) to allow the php code to dynamically produce the html, for the different status values 1-6, you need a way of mapping the status value to the display label - 'New' through 'To Be Invoiced'. i choose to use an array, and since you (probably) want to output each status section, regardless of if there is any data for it, you would loop over this array to produce the sections on the page, then loop over any data for each section. the html, from the <div style="clear:both;"></div> to the end of the page should look more like the following (note: data values that you output to the browser should be passed through htmlentities(). this is not in the example code and is left up to you as a programming exercise) - <?php // define status value to label mapping $status_map = array(); $status_map[1] = 'New'; $status_map[2] = 'Artwork Rec'; $status_map[3] = 'Approved & Ordered'; $status_map[4] = 'In Production'; $status_map[5] = 'Delivered'; $status_map[6] = 'To Be Invoiced'; // query for all the data you want, in the order that you want it $query = "SELECT * FROM jobs ORDER BY status ASC, job_title DESC"; $result = mysqli_query($con,$query); $data = array(); while($row = mysqli_fetch_assoc($result)) { $data[$row['status']][] = $row; // index/pivot the data using the status value - 1..6 } // note: i used some made-up data in the $data array at this point. the above query code should work, but is untested. // loop over the data and produce the output foreach($status_map as $key=>$label) { echo "<div class='column' id='COL_$key'>\n"; echo "<h3>$label</h3>\n"; if(isset($data[$key])) // is there any data from the database for this key/status { foreach($data[$key] as $row) { echo "<div class='portlet' id='ID_{$row['id']}'>\n"; echo "<div class='portlet-header'>{$row['job_title']}</div>\n"; echo "<div class='portlet-content'><a href='pdfs/{$row['pdf_link']}' target='_blank'>View PDF</a></div>\n"; echo "</div>\n"; } } echo "</div>\n"; } ?> </body> </html> next, the jquery you have that is using an id selector - "#portlet" should be removed since this exercise is operating on a class basis, not an id. also, you would not use the update : method, since this triggers for every column that gets updated. if you move something from one column to another, it triggers two times. you need to use the stop : method. see the following javascript/jquery that i came up with - <script> $(document).ready(function(){ $( ".column" ).sortable({ connectWith: ".column", handle: ".portlet-header", cancel: ".portlet-toggle", placeholder: "portlet-placeholder ui-corner-all", stop: function() { var dat = []; var i = 0; $(".column").each(function() { dat[i++] = [this.id,$(this).sortable("toArray")]; // this.id is the column id, the 2nd element are the job id's in that column }); $.ajax({ method: "POST", url: "save_order.php", data: { data: dat } }); } }); $( ".portlet" ) .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" ) .find( ".portlet-header" ) .addClass( "ui-widget-header ui-corner-all" ) .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>"); $( ".portlet-toggle" ).on( "click", function() { var icon = $( this ); icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" ); icon.closest( ".portlet" ).find( ".portlet-content" ).toggle(); }); }); </script> this will submit an array of data to the .php file, in $_POST['data']. see the following example code that extracts the column number and job id (if any), and logs the information to log.txt - <?php // for some reason, the portlet toArray 'adds' an empty element to the start of each array if(isset($_POST['data'])) { foreach($_POST['data'] as $arr) { //$arr[0] is the column id - COL_1, COL_2 (these are the status number 1-6 = New - To Be Invoiced) //$arr[1] is an array of the ids that are in the column - ID_1, ID_5 // get the status (column) number list($not_used,$status) = explode('_',$arr[0]); // get the id's in each status/column $arr[1] = array_filter($arr[1]); // remove empty elements if(empty($arr[1])) { // an empty status/column $str = "Status: $status, empty"; file_put_contents('log.txt',print_r($str,true)."\n",FILE_APPEND); } else { // non-empty status/column foreach($arr[1] as $element) { // get the id number list($not_used,$id) = explode('_',$element); $str = "Status: $status, Id: $id"; file_put_contents('log.txt',print_r($str,true)."\n",FILE_APPEND); } } } }
  16. I was going to ask if you would post a sample of your jobs data, in a php array format (see var_export()), so that we would have something to test with, but in looking at your code, you need to first write a single sql query that gets ALL the data you want in the order that you want it, rather than having 6 queries. then fetch all the data into an array. your code would then loop over that array to produce the output. at this point, you could use var_export() on that array to supply us with some data to test with.
  17. you are closing the database connection inside your loop, which you would know if you spent any time looking at your code. if you had php's error_reporting/display_errors turned fully on, you would be getting an error similar to - Warning: mysqli::query(): Couldn't fetch mysqli in your_file on line x.
  18. it's running exactly what part of what you described 'individually' on 360 products? if you mean the switch/case statement, this is exactly where you were at a little over a year ago - https://forums.phpfreaks.com/topic/297053-switch-statement-taking-a-long-time-to-execute/ each case xyz: statement must be evaluated to find the one that matches the current value and i'm not sure how php finds the next case statement in the tokenized bytecode. if i remember correctly, at the time of that linked to thread, a switch/case statement made up of empty case xyz: break; statements, or at best just an echo or an assignment statement in each case, didn't take that long to execute for all 300 values. however, if php must scan through all the tokenized bytecode to find the token that identifies the start of each/next case : statement, for your actual code, with several statements inside each case, this would take a noticeable and progressively longer time the further down in the list of case statements php must search to find a match. converting to the rules based code that i have suggested will eliminate the switch/case statement. you will still be looping over a set of values, but you will be directly using those values in a function/method call. the time taken for the code execution for each set of values will be the same.
  19. First of all, your question is about php code, don't know why you posted this in the HTML forum section. You can install all-in-one xAMP (x = W, M, L for Windows, Mac, Linux, AMP = Apache, Mysql/MariaDB, Php) development packages on any current PC and operating system. see this link - https://www.apachefriends.org/index.html
  20. web servers are stateless. all the code and query(ies) you have described start over and run again for every request you are making to the server. an ajax request is still a request to the server. the only thing that may be helping in this case is if the queried for data is still in the database server's query cache, it will be returned from the cache rather than actually executing the query against any database tables. for you to cache the queried for data in the php code and eliminate touching the database server for it, would require that you store the data in a session variable. edit: also, for it to take multiple seconds for this code/query to run once indicates there is some problem, either in the db table design, the queries, or in the php code.
  21. are the objects created in session variable(s)? if they are not, they are are all destroyed when the server-side code execution ends, which is at the end of each http request, and they are all re-created for every http request.
  22. well, there you go. you would need to find where the Mail class is being defined at and find out why it isn't being defined for the current code. it's not a native php class, so it would be either explicitly required/included or there would be an auto-loader that requires the file containing the class definition.
  23. btw - your select name attributes - name="qty189" should be a html array - name="qty[189]". this will allow you to easily loop over the data using a php foreach(){} loop.
  24. assuming that you want to look at all the select/option menus and they all have class='qty', you would loop over each of the elements with that class - $(document).ready( function() { $('input[type="image"]').click( function() { var total = 0; $( ".qty" ).each(function() { total += Number($( this ).val()); }); if(total == 0) { alert("You have not selected a product quantity!"); return false; } }); });
  25. you are probably getting a fatal run-time error at either the Mail::factory() or $smtp->send() statement. have you done the following -
×
×
  • 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.