Jump to content

Psycho

Moderators
  • Posts

    12,145
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. It is my understanding that a timestamp is the correct type if the "event" is one that must be normalized based upon a given user's timezone. A datetime is one that would be statis regardless of timezone. For example, if I am recording the date and time that someone is born, you would display the exact same date and time to a user regardless of their locale (a datetime type). Otherwise, my birthday would be a day earlier if I traveled to Europe. Conversely, if I was to record the date and time of when a specific event was to occur, such as the super bowl, I would use a timestamp so it could be displayed as to the correct date and time relative to the user.
  2. To add to requinix's response: Since you mention "time" in your post, it is very important to know whether you want to subtract 30 calendar days or if you want to subtract 30 days (i.e. 30 x 24 hours). It will likely depend on "how" the value(s) are used. This is due to Daylight Savings time that is used in some parts of the world. Let me give two examples that would need to be handled differently. Scenario #1: Let's say you want to run a report from a specific date/time back 30 days. If the user expects to run the report at 5PM (close of business) today to see a report of all activity from 30 days ago at close of business - the logic needs to subtract 30 calendar days, but set 5PM as a constant. Scenario #2: An application that needs to track the status of an activity over very specific times would likely be different. For example, say there is an experiment to measure the results over hours/weeks/months. If I wanted a report for the results over 30 days it would need to take into account time changes due to daylight savings. So, if I wanted the report to end at 5PM today, it would need to start at 6PM on the calendar day 30 days back. That is because last weekend we set the clock back an hour last weekend (i.e. we repeated the 1AM to 2AM hour).
  3. Well, you could use GROUP_CONCAT() which will concatenate the values within a grouped record. But, it has some limitations. For example, I don't think it will remove duplicates. BUt, there are other, more technical issues. that I don't want to go into details with. If you need those values, then I would suggest just selecting all the records instead of getting calculated totals. Then when outputting the results, get the totals. Using GROUP_CONCAT SELECT pseudo, SUM(nmbr) as score, GROUP_CONCAT(DISTINCT player_name ORDER BY player_name ASC SEPARATOR ', ') as player_list FROM unanimo INNER JOIN ( SELECT mot , COUNT(*) as nmbr FROM unanimo GROUP BY mot HAVING nmbr > 1 ) tot USING (mot) GROUP BY pseudo ORDER BY score DESC; Or, just query all the relevant records without the GROUP BY and handle the logic to calculate totals and determine the player list in the code.
  4. I'm not an expert in CSS. There may be a better way but this works (tested in Chrome). Of course you would likely need to modify the styles further to get the actual look/feel of the content and boxes as you like. but, it does create the look of the little sub-dialog boxes peeking out at the bottom. I would create those within the server-side code using smaller increments for the width. Everything else can be done through the CSS style sheet. <html> <head> <style> #container { display:inline-block; width: 300px; } #dialog { border: 1px solid #000000; text-align: center; } #title { background: blue; width: 300px; color: #ffffff; } #body { height: 100px; } .subDialog {height: 5px; border: 1px solid #000000; margin: 0 auto; } </style> </head> <body> <div id="container"> <div id="dialog"> <div id="title">Dropbox</div> <div id="body"><br>4 Files were updated in your folder<br><br><button>View Folder</button></div> </div> <div class="subDialog" style="width: 290px;"></div> <div class="subDialog" style="width: 280px;"></div> <div class="subDialog" style="width: 270px;"></div> </div> </body> </html>
  5. The fields are updated in order, so be sure to have the pad_count updated first in the query. Then the update to the cn1 field would use the 'current/new' value of pad_count UPDATE users SET pad_count = (pad_count + $add_pad_count), cn1 = CONCAT('cn', pad_count) -- will use the new pad_count value set on the line above WHERE username = '$session->username' EDIT: In retrospect, this is unnecessary to have pad_count and cn1 fields. You can always get the cn1 value from the pad_count. Either by dynamically creating the value in the select query or generating the value in the PHP code from the pad_count. Dynamically creating cn value in SELECT query. SELECT pad_count, CONCAT('cn', pad_count) as cn_value FROM users
  6. I'm not really following. First of all, there should be no reason to run two queries. Are you wanting to set the field cn1 to the string value of "CN" concatenated with the new numerical value for pad_count? For example, if the exising pad_count value equals 10 and the $add_pad_count is 5: do you want to set pad_count to '15' and cn1 to 'cn15'?
  7. Have you connected to the database? If not, mysql_real_escape_string() will not work (But, you should not be using the mysql_ functions anymore anyways). My guess is that the function is failing and returning FALSE (The Boolean value, not the string). Try running this to verify what, exactly $score contains: var_dump($score);
  8. In other words, find the code that inserts those records and do the replacements on the text before the data is inserted. Once the problem has been fixed at the source, you can then run the necessary REPLACE queries to resolve the existing data.
  9. You stated the objective was to retrieve the records. I assumed you would have a script that would select the records then perform some actions that included DELETE - e.g. possible apply the labels of the duplicates to the original if needed. I'm not following. The first query I provided should return the records from the food_tags table associated with foods that are duplicated (excluding the original food records). Which is exactly what you stated in your objective. Perhaps you can provide a small subset of example data and what you expect to have returned (deleted)?
  10. And why wouldn't you want to fix the schema? I know you stated " . . . let's assume that these options are not available". But, many times people come here asking for a complicated solution for something that was built incorrectly because they can't conceptualize the correct solution. Then the people helping spend time providing something that is less than optimal. Or, we spend a lot of time trying to dig to the source of the issue and have to guide the OP to the better solution. Not sure why you only want the tags of the duplicates and not the first record. Are you using an existing query to get the tags of the original and are wanting the tags of the duplicates to append them together? Anyway, what you are asking is quite simple. Here is the query to get ALL the records from food_tags associated with 'duplicate' records (excluding the original record that is duplicated) SELECT * FROM food_tags WHERE food_id NOT IN ( SELECT MIN(id) FROM foods GROUP BY name ) Here's a version with JOINs to show descriptive values SELECT foods.name, foods.id, tags.name, tags.id FROM food_tags JOIN foods ON foods.id = food_tags.food_id JOIN tags ON tags.id = food_tags.tag_id WHERE food_id NOT IN ( SELECT MIN(id) FROM foods GROUP BY name ) ORDER BY foods.name, foods.id
  11. There is always a different way, the question is if there is a better way or not - and in this case there is. I was actually going to speak to the same problem that I'm sure benanamen was going to address, but decided against it once Ch0cu3r responded. You should not have data where there is an assumption of correlation based on position. This is bad form and will eventually lead to bugs. Instead, the correlated data should be structured such that the correlation is specifically defined. In this case you have pairs of fields that should be correlated within the structure. Using a multidimensional array was the right choice - but I would swap the keys so that the records are logically structured. But, instead of "[]" you will need to define the key. E.g. <input type="text" name="productVariations[0][name] /> <input type="text" name="productVariations[0][price]" /> <input type="text" name="productVariations[1][name] /> <input type="text" name="productVariations[1][price]" /> <input type="text" name="productVariations[2][name] /> <input type="text" name="productVariations[2][price]" /> I'm sure I've left off some content that goes between the fields and, ideally, the output would be generated within a loop. using that structure, the array of the post data would look like this productVariations array ( 0 => ("name" => "Default", "price" => "12.99"), 1 => ("name" => "100ml", "price" => "9.99"), 2 => ("name" => "150ml", "price" => "14.99") ) Then the code to process the data could look like this foreach($productVariationsAry as $record) { $name = $record['name']; $price = $record['price']; // do insert query } FYI: It would also be more efficient to create ONE insert query to insert all records at one.
  12. There is no definitive way to know that a user is "online". A server doesn't know what the user's state is between one page request and another. All you can do is store a timestamp for each page request and if a user has not requested a page in (some time that you define) assume they are no longer on your site. Now, you *could* implement some JavaScript to make an AJAX call every X minutes to better know when they are not on your site, but the overhead of doing that is not worth it. EDIT: Also, do not DELETE records when you "think" they leave. Just use the last timestamp as the last time the user has made a request. Delete's are big performance hogs and there is no need for it in this context.
  13. There's quite a few things which need to be "fixed" in this code, not the least of which is the password verification. But, we can start with that. When a user creates their password, use the function password_hash() to generate a hash value and save it to the DB. Then, when a user attempts to log in, run a DB query to find the record matching just the username. Take the hash value from the DB and the password the user provided on the login and use the password_verify() function to see if the password is valid. FYI: Font tags have been deprecated for over a decade!
  14. Give this a try <?php if (!empty($results)) { foreach ($results as $row) { echo "<tr>\n" echo " <td>{$row['user_nome']}</td>\n"; echo " <td>{$row['user_email']}</td>\n"; echo " <td>{$row['user_tel']}</td>\n"; echo " <td><a data-toggle='modal' data-id='{$row['user_id']}' class='open-AddDialog btn btn-sm btn-danger center-block' href='#myModal'>Validar</a></td>\n"; echo "</tr>\n" } } ?>
  15. You have an 'echo' inside the quoted text. Couple that with the fact that you start the string with a single quote and then put an array with a single quoted index inside the string, the PHP parser is confused (as am I). Also, why do you have this? if (empty($results)) { } else { There is no purpose for the TRUE branch of that statement. Just use this ]if (!empty($results)) { Although, if $results is just an empty array, you don't need the empty check at all - just run the foreach. EDIT: You are also creating some invalid HTML code. There is no closing TD for one element - and I would expect a closing TR on each foreach as well.
  16. There are many characters that can legitimately be within and at the end of a sentence " . . . just like in literature". If this is for a real-world application that will presumably produce an error for sentences entered by users, you are going to have the very likely possibility of false negatives.
  17. Short answer, No. You could either learn enough to accomplish what you want to achieve or find someone who will do it for you (possibly for a fee). But, I can provide some insight as to the problem. When a request is made to a server for a PHP page, the server will complete all of the action within that script (and included scripts). Once all processing is complete it will then send the completed page to the user. There are a lot of exceptions to that, but for your situation it applies. Then once the user's browser receives the page, any JavaScript in that page can then execute. The solution to your problem would likely be to make an AJAX call to get the RSS feed data. So, the page you have now should just create a container to put the RSS output and remove the PHP line that goes to get the content. Then, in addition to having JavaScript code to preload the images, you would implement an AJAX call to a PHP page to just return the RSS content that you would then populate on the page with JavaScript. This may sound complicated, but there is a framework called JQuery that would make this rather easy. But, if you don't know any coding it could take a while to figure out how to implement it. http://api.jquery.com/load/
  18. What is the difference between the two manners in which you are referencing the value?? Hint, one of these things is not like the other:
  19. shan, Your description does not provide any real help in understanding what you are needing help with. I'm sure it makes perfect sense to you as you are fully engaged i the code and the problem. But, your statement doesn't make sense to those of us without any context. Also, just copy/pasting a lot of code suggests you expect those providing free help to try and read through all that code to figure out what the problem may be. Please try to identify the specific part of the code causing the problem, what that code is currently doing, and what you expect the code to do.
  20. benanamen is correct, tables should not be used for the purpose of layouts. But, to provide an answer to your problem - colspans do not apply to TR tags. A TR is just to define a row. The rowspan attribute applies to TD elements to state whether they should take multiple columns. So, you could do the following: - Add a colspan="2" to the Organization name TD - Add a collspan="3" to the last TD in each row starting with the Fax number
  21. The request would be server -> payment gateway, not client -> server. Exactly! The 3rd party site has to provide the CC processor with the amount to be charged. What we are talking about here is an ordering workflow where the application calculates the order total at the beginning of the checkout process and then passes that total through several pages to complete the order. It is a fairly simple task to manipulate values in a hidden field. So, it would be foolish to rely upon that calculated value once it is submitted from the client to the next page. Just calculate the total and stare it as part of the order in the DB.
  22. "Critical" in this sense is any data that you do not want the user to control or have access to. Amazon wouldn't calculate the total for your order and then populate a hidden field with that value to propagate the total through the pages to complete the order. If they did, there would be thousands of people placing orders with a cart total of $0.01 by manipulating the data.
  23. And what problems are you having with your current code? Your explanation is unclear. When you say " . . . if published year comes before the birth year, append this entry to a new text file." I have no idea what you mean. Are you wanting to edit the text file being read to remove that content and put into a new text file? If so, how to determine what the new text file will be named? As far as You will need to read all of the data into an array and then parse the values to find those records. Or, you could put this data into a database where it belongs and make everything much easier.
  24. $myName = 'Alison'; $maxLetters = strlen($myName); $randIndex = rand(0, $maxLetters-1); $randLetter = substr($myName, $randIndex, 1); echo "Random letter from \$myName '{$myName}': Index {$randIndex}, Letter {$randLetter}";
  25. Read the manual. The substr() function only takes one parameter for the start position. So, if it was to go from 0 to n from the right side it would then need another parameter to know if the index is from left to right or right to left. Instead, positive numbers indicate left to right and negative numbers mean right to left. Look at all the examples in the manual and it should start to make sense for you.
×
×
  • 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.