Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by Psycho

  1. OK, let me see if I understand the problem correctly. If the user enters values for gpm and ewt AND there is a record that exactly matches both of those values, then you want the totCool value for that record. However, if there is no exact match, but either gpm or ewt does match records, then you want the average of totCool for the two records above and below the unmatched value. There are two scenarios that are unclear. What do you want to do if neither gpm nor ewt match any records? What should happen if one value matches, but for the unmatched value there is no record above (or no record below) to use to calculate an average?
  2. Based on the request, I see that Barand's code works as required. However, I would do one thing differently. The lines to determine the afc and nfc positions in the loop are perfectly valid, but the calculations are not intuitively apparent. While maybe not as efficient, I prefer code that is more obvious, such as echo '<hr>Matrix table<br>'; for ($afcPos=0; $afcPos<10; $afcPos++) { for ($nfcPos=0; $nfcPos<10; $nfcPos++) { $coord = $afcPos . $nfcPos; $afcVal = $afc[$afcPos]; $nfcVal = $nfc[$nfcPos]; printf('| %02d | %d, %d<br>', $coord, $nfcVal, $afcVal); } } Although you state If this is going into a database, you should just need a table that defines each player and the coordinates of the position(s) they selected and a second table that defines the randomly generated numbers and their positions. You do not need to go back and update the player records with the number associated with their positions.
  3. The lesson instructions state to create an associative array.
  4. I am pretty certain that your source array is not constructed how the instructor intended. You are simply assigning an array of values to each associative key. I would think the source array should have an element for each employee with each value assigned to an associative key. Something like this: $employees = array ( array('name' => 'Employee-1', 'department' -> 'IT', 'salary' => '5000'), array('name' => 'Employee-2', 'department' -> 'HR', 'salary' => '4000'), array('name' => 'Employee-3', 'department' -> 'Marketing', 'salary' => '3000'), array('name' => 'Employee-4', 'department' -> 'Sales', 'salary' => '1500'), // etc. . . . ); The loop over each record in the $employees array foreach($employees as $employee) { echo "Name: {$employee['name']}<br>"; echo "Department: {$employee['department']}<br>"; echo "Salary: {$employee['salary']}<br>"; }
  5. Have a table for comments which contains a unique record for each comment/reply: comment_id (id for each comment/reply) post_id (the ID of the post that the comment/reply belongs to) reply_id (The comment Id of the comment being replied to, or empty/0 if it was an initial comment) user_id datetime comment . . . any other relevant info
  6. Here 0is how I would handle that function columninfo($table, $col = NULL) { //State the error condition check if(!$this->CheckTable($table)){ return false; } //State the error condition check if($col!=NULL && !$this->Checkfield($table, $col)){ return false; } //No errors $stmt = $this->db->prepare('SELECT * FROM '.$table); $stmt->execute(); $numCol = $stmt->columnCount(); $colAry = array(); for ($i = 0; $i < $numCol; $i++) { if($stmt->getColumnMeta($i)['name'] == $col) { //Return type for selected column return $stmt->getColumnMeta($i)[0]; } else { //Append current column to return arrray $colAry[] = $stmt->getColumnMeta($i); } } //Return array for all columns return $colAry; }
  7. Generally, I would agree with that. However, I wonder if there would be legal reasons for keeping a copy of the invoice that was sent. Yes, another copy could be generated later and would be the same - if the code had not changed. But, if there was any type of legal action and the company needed to provide records of the invoices that were sent, I don't know if regenerating a copy would be adequate. They might have to also prove that none of the code changed that generated the invoice and if the code had changed they might have to prove what the invoice would have looked like at the time it was generated previously.
  8. Most definitely different character sets (aka fonts). You can tell by the lower case L's in the variable name:
  9. I'll add to @requinix's response. As he said, the easiest approach would be to have a save button that loops through all the rows in the table (except the header) and executes the save individually. Your current save operation only requires an id value. So, I would leave the current save_row() functiona unchanged and then do two things: In the script that builds the table, create a hidden field with the value being the ID Create a new function [e.g. save_all()]. Have that function iterate through every row in the table and get the ID value and execute the save_row() function However, as he said if you have "lots" of rows, this may not be a good approach because each AJAX call would have to be performed separately. You would have to do some testing with the maximum number of records you expect to have to see if it will be an issue. If so, I would take a different approach. I would make the values in the rows actual input fields - making the field names an array. Something like: echo "<input type='text' name='records[{$row_coun_fin['PRODUCT']}][remarks_val]' value='{$row_coun_fin['REMARKS'];}'>"; Then you can submit the whole form via a normal POST or via AJAX. Then the receiving page would just need to iterate over the $_POST['records'] array foreach($_POST['records'] as $productID => $productData) { //Update the data for the current record from the values in $productData }
  10. You are making things harder than they need to be. Why are you including the sales_order table in your query when you don't use any data from that table and you can use the lookup value on the sales_order_lines table? Why do you iterate through the DB results to put them into other arrays just to iterate over those? $sql="SELECT `name`, `quantity`, `delivery_date`, DATE_ADD(`delivery_date`, INTERVAL 10 DAY) AS used_day FROM `sales_orders` so INNER JOIN `sales_order_lines` sol WHERE sol.`parent_id` IS NULL AND sales_orders_id = '$id'"; $result = mysqli_query($connect, $sql); $degree = "STORAGE: KEEP REFRIGERATED BELOW 5`C"; //var_dump($degree); $labels = ""; while($row = mysqli_fetch_array($result)) { $curent_label = sprintf( "%s\n%s %s\n%s %s\n%s\n%s", "{$row['name']}","<br>", 'Delivery Date', "<br>", 'Use By Date', "<br>", "{$row['delivery_date']}","<br>", "{$row['used_day']}","<br>", 'PRODUCT OF SOUTH AFRICA',"<br>", "{$degree}" ); $labels .= str_repeat($curent_label, $row['quantity']) } echo $labels;
  11. Adding a try/catch or die to every single place that an error could potentially occur would probably be an exercise in futility. You say that your shared server has no error logs. You could try adding code to your page(s) to generate an error log. Put this code somewhere so that it will be executed on any page load: ini_set("log_errors", 1); ini_set("error_log", "php-errors.log"); You could then have a separate bowser window open to the location of the error log and refresh it upon any page load to see what errors may have occurred.
  12. With a web application, you can certainly record when a user logs in, but even if you have a logout function a user can simply close the browser window. So, you do need a way to track that they are still there. Since this is a game where two people are playing each other, I think you need to do more than just track when they hit a new page. Here is what I would do: Create a last active field in the user table. Every time you see activity from the user, update the timestamp. Determine "how long" of a time period that you would consider someone as still active: 5 minutes, 10 minutes, ??? Then use that time period to query for active players based on those whose last active timestamp is within the last X minutes. This can also be used for two players already in a game to notify one that the other has dropped off. Once two users start a game use AJAX to both continually update their last active value AND to proactively notify them of anything relevant. E.g. when it is their turn, if the other user drops off, etc. AJAX is simply javascript that makes a server call and returns back data to the user which you can then implement additional logic to act on that returned data. You can update the content in their browser window based on the move the other player made, make a notification, whatever. In this case, I would have the AJAX make a call every X seconds (10, 20, 30 ???). That call would do several things: Update the last active timestamp for the user Check if the other user is still active. Since the other player will also have AJAX running, their last active timestamp should never be greater than the time you set for the AJAX calls to be made. So, if the other players last active timestamp is more than double that time period, I would let the user know that the other user has dropped Check if the other user has made a move (if it was their turn). If so, alert the user that the other user has made their move, show the results of that move, and tell the player it is now their turn. I'm sure there are some things I am leaving out, but the core of it is to use regular calls via AJAX to determine when users have completed a turn and to ensure they are still online. Be sure to use a JavaScript framework to do this (such as JQuery) instead of trying to build the AJAX code with native JavaScript.
  13. It's been at least a decade since I played around with the getid3 library. I'll be honest, I have no idea what ETCO tag data is. But, I have a possible solution. Do you have a file with existing ETCO tags or is there a tag editing application that you can use to set such tags? If you have a file with example tag data that you know what it represents, then instead of using getid3 to set the data, use it to get the data. You can then see what the format of the data is that it expects. I remember doing something similar for some other tag information at the time.
  14. while($cash_on_hand <= 35) Well, that loop is not set up per your instructions. You declared $cash_on_hand twice then in the while condition you hard coded the value (35) instead of using the variable. That loop will run infinitely because $cash_on_hand will always equal 35. You need to calculate $cost on each iteration of the loop and compare that to $cash_on_hand. To be honest, I don't like the instructions given because they require you to define the calculation for $cost at least twice (you should never write code twice - write it once and call it many times). $cash_on_hand = 35; $meal = 25; $tip_percent = 10 $cost = $meal + $meal * ($tip_percent / 100); $cash_on_hand = 35; //Remove this while($cash_on_hand <= 35) { //Fix this to test the condition in the instructions echo "I can afford a tip of $tip_percent%, for Total Cost: $cost <br/>"; $tip_percent++; //Add a recalculation of $cost here }
  15. No way to tell from the code provided as to why you are getting a blank page. That code produces no output. It attempts to set a header value and then redirects to another page. I say "attempts" because I don't see any code where you actually start a session before trying to save a session value. Part of coding is learning to debug. Rather than assuming your code works and redirecting to another page, try outputting to the page for BOTH the success condition and the error conditions. Then, based on those results you can then ad the additional code to redirect or whatever you want. What does the following output? if ($result) { //$_SESSION['messages'][] = 'Thanks for registering. Check your email to confirm your email'; //header('Location: register.php'); //exit; echo "Success saving record with the following values:<br>\n"; echo "usernamebox: '{$data['usernamebox']}'<br>\n"; echo "emailbox: '{$data['emailbox']}'<br>\n"; echo "passwordbox: '{$data['passwordbox']}'<br>\n"; } else { echo "Error attempting to save record with the following values:<br>\n"; echo "usernamebox: '{$data['usernamebox']}'<br>\n"; echo "emailbox: '{$data['emailbox']}'<br>\n"; echo "passwordbox: '{$data['passwordbox']}'<br>\n"; }
  16. I would also highly recommend not referencing database results based on the numeric index and instead referencing results based on an associative array (i.e. named indexes based on the field names). It makes for more readable code and is much, much easier to maintain. The sample code by Barand uses such an implementation.
  17. Not sure if this is the cause of your problem, but your UPDATE query is using the email address in the WHERE calus to determine which record to update AND it is attempting to overwrite the email address. I see no reason why that wouldn't work, but why would you do that? In any event, MySQL has you covered with the INSERT ... ON DUPLICATE KEY UPDATE Statement. Such a statement will attempt to insert a new record But, if the insert would fail because of a duplicate key (e.g. $stdEmail) then the statement will update the current record based on the conditions provided. No need for an initial query to see if the record exists - just run the ONE query. INSERT INTO semakan_dokumen (email, surat_tawaran, ic, sijil_lahir, sijil_spm, sijil_sekolah, sijil_dip, sej_julai, bm_julai, muet, mid1, yuran, umpa_bend1, umpa_bend2, bpkp, penaja, kesihatan, jhepa) VALUES ('$stdEmail', '$fileName', '$fileName1', '$fileName2', '$fileName3', '$fileName4', '$fileName5', '$fileName6', '$fileName7', '$fileName8', '$fileName9', '$fileName10', '$fileName11', '$fileName12', '$fileName13', '$fileName14', '$fileName15', '$fileName16') ON DUPLICATE KEY UPDATE student_id = '$noMatrik' surat_tawaran = VALUES(surat_tawaran), ic = VALUES(ic), sijil_lahir = VALUES(sijil_lahir), sijil_spm = VALUES(sijil_spm), sijil_sekolah = VALUES(sijil_sekolah), sijil_dip = VALUES(sijil_dip), sej_julai = VALUES(sej_julai), bm_julai = VALUES(bm_julai), muet = VALUES(muet), mid1 = VALUES(mid1), yuran = VALUES(yuran), umpa_bend1 = VALUES(umpa_bend1), umpa_bend2 = VALUES(umpa_bend2), bpkp = VALUES(bpkp), penaja = VALUES(penaja), kesihatan = VALUES(kesihatan), jhepa = VALUES(jhepa)
  18. You forgot the next line. The full bit of code you had is if (isset($_POST['submit'])){ //if form submitted $ppp=$_POST['ppp']; //assign value from select box }else{ $ppp=15; //default number of posts-per-page } $_SESSION['ppp']=$ppp; //session index created with new number of posts-per-page If there is no POST submit, then $ppp is set to the default of 15. Then, the last line, is setting the session value to that same default of 15. It NEVER checks to see if there is an existing session value. It will simply overwrite any previous session value. The code needs to work in this manner: Check if the user submitted a new ppp value. If so, set the 'working' value in the script and set the session value If not #1, check if there is a saved session value. If so, set the 'working' value in the script If not #1 or #2, use a default. In the code I provided, I set the default first and let the logic for #1 and #2 overwrite the default. I don't know why the code is not working for you. There is obviously something in the code that you have not provided. But, here are some other comments: Why are you checking for $_POST['submit']? You only need to check for $_POST['ppp'], since that is the value you would be working with As Barand stated, and I alluded to, NEVER trust data from the user. It is a trivial matter to pass a value that is not in a select list for a form field, to add other field value in a form request, remove others, pass values that would have been validated on the client-side, etc. For a select list, I suggest having a defined list (such as an array in a config file) and use that list to a) Create the select list and b) validate that the user passed an approved value. So, put the code to check for a POST ppp value, or a session ppp value or to use a default at the top of the script before you need the ppp value. Not sure why this is a question.
  19. @dunno You start by referring to page1 (the form page) and page2 (the page to shows the posts per page). But, in response to Barand's reply you show the code where the session value is set, but don't explain where that code is run. Is that code on page1, page2, or some other page? If that code is executed on every execution of page2, then it will reset the ppp value to 15 whenever the user doesn't select a new ppp value since you are ALWAYS resetting the session value - even when the user did not submit a change. If that code is on an intermediary page (a third script) - is session_start() initiated on that page? EDIT: I'm going to assume that the code to set the ppp session value based on the user's submission is at the top of the script that displays the posts. In that case, you should change the logic like this: //Set list of APPROVED ppp values (prevents users from submitting arbitrary vaues) $pppValues = array(10, 15, 20, 50, 100); //This array should be in a config file and ALSO used to create the select list options //Set default value of $ppp value $ppp = 15; //Check if user submitted new ppp value (that is in approved list) if (isset($_POST['ppp']) && in_array($_POST['ppp'], $pppValues)) { $ppp = $_POST['ppp']; //Assign value from POST submission $_SESSION['ppp']=$ppp; //Set value in session (only set if user submitted new value) } //If user did not submit new ppp value, check if ppp value already set in session elseif (isset($_SESSION['ppp']) { $ppp = $_SESSION['ppp']; //Assign value from session } //Rest of script can use $ppp to display correct number of posts @Strider64 Not sure what you mean. Session values are a common process of keeping values static between page loads. No need to store the value in a config value.
  20. I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called.
  21. So, as I understand it, the user is adding multiple line items for an invoice and THEN you redirect at the end. Why? Here is what I suggest you do. User navigates to a CREATE_INVOICE page On first entry there will be no GET value for the invoice ID, so display whatever initial instructions/content to be displayed to the user. E.g. it could provide a form for vendor name/address, PO number, etc. User submits the form using POST The receiving page identifies that this is a new invoice and add the applicable header records to the DB and generates an invoice ID The receiving page then performs a redirect to the CREATE_INVOICE page with a GET value for the invoice ID The CREATE_INVOICE page detects the invoice ID and displays the current invoice data (including any line items already added), The page also displays a form to add a new line item. The user will have two options. 1) Enter data into the fields for a new line item or 2) Complete the invoice If the user enters a new line item, it sends the form data (using POST) to the processing page which adds the new line item and then performs a redirect using the invoice ID as a GET value. This takes the logic back to step 6 and will repeat indefinitely until the user decides to complete the invoice
  22. 1. Create a function that takes the excel file as an input and performs all the operations you want to do to the excel files 2. Use a process to loop through all the excel files: scandir(), readdir(), . . . ??? 3. Upon each iteration of the loop call the function in step #1 passing the current file as a parameter
  23. Try putting this bit of debugging code in your script right before your if() statement. What does it produce when you run the script? if(!isset($_SESSION)) { echo "Session was not started yet"; } else { echo "Session data:<br>"; echo "<pre>".print_r($_SESSION, true)."</pre>"; }
  24. You really need to analyze the source data to identify the different data and types of issues that can exist in order to determine the appropriate solution. For example, the solution @Barand provided would be acceptable if: 1) The only issues are missing closing tags 2) None of the "data" contains a greater than sign If there are other types of issues or if data can contain the < symbol then a different solution is in order.
  25. To add to @requinix's response, the communication to the database would be between the PHP server and the database server. The client should have no idea about how the connection is made. However, if you have "holes" in your application that allows the users to infiltrate your server-side code, then all bets are off. Unfortunately, the guidance on not creating those holes is an expansive subject. A forum is great for asking abut specific aspects, but for the big picture I would suggest looking for training and/or guides on the subject.
  • 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.