Jump to content

Psycho

Moderators
  • Posts

    12,146
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. @NotionCommotion: Use a UUID: http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_uuid mysql> SELECT UUID(); -> '6ccd780c-baba-1026-9564-0040f4311e29'
  2. <?php session_start(); //Define array of messages $messages = array( "Oh. Hello there. How'd you get in here? Oh well, just please don't push that button, okay?", "What are you doing?! I just said not to touch that! Leave it alone now!", "Stop! Are you trying to kill us all?! Get away from there!", "Okay, let's start over. We're obviously off to a bad start. Hi. My name's Tim. I work at this lab and it's my job to ensure that button is never pressed.", "Ha..Ha..Ha.. Okay now. Don't do anything hasty. What's got you feeling so down that you want to go and kill everyone, huh?", "Please stop pushing that button. Talk to me. Tell me what's wrong buddy. I won't judge you, I swear.", "Come now. What could possibly be so bad that you'd want to kill everything? Is life really so hard? Why won't you speak to me?", "I'm sorry but if you continue pressing that button, I'm going to call security and have you forcibly removed from the premisis.", "What's this? So you don't believe I'll actually do it? Fine. GUARDS! Come quick! There's a maniac in here trying to destroy us all!", "Well I hope you're happy. I don't like being the mean guy, you know? I just wanted to be friendly, I don't get any visitors. But now look what you've gone and made me do. They should be here any minute now.", "Would you stop hitting that button already? It's over. They're coming to get you and take you away. You're most likely going to be sent to a maximum security prison for breaking in here you know.", "Yup. Any minute now. So you might as well stop hitting that button. The jig is up. I think I hear them now. It sounds like they're carrying some big guns too. I'd suggest just laying down and giving up now. But no, you just keep on hitting", "Okay, stop. This is getting ridiculous. Just give it up and relax while you wait for my guards to take you away. They'll be here any second. Any second now.", "Yup. Any time now..", "Yup. Any... Okay you got me. I don't have any guards. But you seriously need to stop hitting that button. Actually, go ahead and hit it. I don't care anymore. Just keep pressing it. See if I care.", "Nope. Go ahead. Push it some more. I wont try to stop you. It's not like I have anything to live for anyways. I have no wife, no kids. I live in this lab; that's my bed over there. I've never had a girlfriend, not even a real job. All I do is sit here and stare at a button all day.", "Yeah, that's right. Blow this place up. Kill everything like the little button pushing demon you truly are.", "Wait! I changed my mind! I don't want to die. I want to live. I want to get a girlfriend. I want kids. I want a house of my own, somewhere off in the country so my children can run and play all day. Please, if you have any humanity left in you at all, please don't push that button anymore.", "PLEASE! Stop it! Oh god! You won't listen will you?! You're going to kill all of us! Stop it! Oh god the clicking! I can hear the cliking of that button in my head! Make it stop! MAKE IT STOP!!", "OH GOD!! The noise!! MAKE IT STOP!!! ARRRGH!! ROCK PAPER SCISSORS SHOOT!! What am I saying?! Why are you doing this to me?! STOP IT!! GET OUT OF MY HEAD!!", "ARRRGGGGH!!!! I'M GOING TO KILL YOU ALL!! STOP THE NOISE!!!! I CAN HEAR IT!! YOU'RE DOING THIS TO ME!!! STOP IT!!!!", "GRAHH!! DIE! DIE! DIE! *Tim charges you and tackles you to the ground. As you black out from the heavy head impact the last thing you see is Tim bearing down on your throat with a scalpel.", ); //Dynamically determine total button presses $totalButtonPresses = count($messages); //Set starting button presses if needed if(!isset($_SESSION['presses_left']) || isset($_GET['refresh'])){ $_SESSION['presses_left'] = $totalButtonPresses; } if($_SESSION['presses_left'] > 0) { //Determine message to display $messageIndex = $totalButtonPresses - $_SESSION['presses_left']; echo "<h3>{$messages[$messageIndex]}</h3>"; echo "Button presses left until the end of the world: {$_SESSION['presses_left']}<br/><br/>\n"; //Reduce presses left $_SESSION['presses_left'] -= 1; echo "<a href='page_load_counter.php'><button>Launch Missile</button></a><br/>\n"; } else { echo "<h3>Boom!</h3>"; echo "<a href='page_load_counter.php?refresh'><button>Reset</button></a>"; } ?>
  3. I'm confused on your explanation. You keep stating you want to use the "highest" three numbers to generate a fourth. But, all of your examples just happen to have the highest (largest) numbers in the last position. So, it is not clear if you are talking about the three numbers with the greatest value or the ones in the last positions of the array. Also, you keep stating the generated value should be based on three numbers, but the logic you have presented only seems to use two. EDIT: Also your explanation of the rules to determine the number are a mess. You state rules when the 4th and 5th numbers are equal to each other, but then give examples where they are not equal to each other. I would think that for a lottery they would never be equal.
  4. What do you mean by "the first row"? Are you saying there is an HTML table on the page and the word would exist within the first TR instance? If so, does it exist within a specific TD instance in that row (e.g. the first, second, third, etc.). Is the word the only thing in the TD container or is there other content? What are the other potential words that might be in that same place? There are too many variables for me to provide a solution without knowing more. Provide a sample of the HTML code where the word exists and the word you are looking for and I can give you something.
  5. [i removed the other post] Yes, it is possible. "How" you do it would depend on the structure of the page and how the word exists in the page. For example, if the word you are looking for is "car" you wouldn't want to just look for those three letters in succession. Otherwise you would find "carpet" as well. Perhaps the word you are looking for would be contained within a DIV on the page. If so, then you would write the code to look specifically for that div and within the div for the content. This is typically referred to as screen-scraping. Depending upon what you are doing and how you use that information, you may be violating copyrights or terms of use for the site in question. At worst it could be illegal. It may just be immoral/bad etiquette. Or, if the owner/author is OK with it and you are not reusing the content and presenting it as your own, then it might be OK. Bottom line - tread carefully.
  6. You should check the REQUEST_METHOD to determine if a POST was made instead of some arbitrary field. You would still need to validate that all required fields have data anyway. I know that in some older browser an input submit button would only be included in the POST data if the user actually clicked on the button (as opposed to pressing the enter key on the keyboard which would also submit the form). Also, I would highly suggest changing the conditions to check for the negative conditions so you can put the error message next to the condition that checks for it. Otherwise, you create all these nested conditions making it difficult to "see" which message goes with which condition. This is the structure you have now if(condition1) { { //Do something if(condition2) { //Do something if(condition3) { //All conditions passed } else { echo "Error condition 3"; } } else { echo "Error condition 2"; } } else { echo "Error condition 1"; } This is much cleaner: if(!condition1) { { echo "Error condition 1"; } else { //Do something if(!condition2) { echo "Error condition 2"; } else { //Do something if(!condition3) { echo "Error condition 3"; } else { //All conditions passed } } }
  7. thara, you are missing the point. There was nothing, specifically, wrong with the query you were using in post #3. What Barand was asking was if the existing record actually had an id of '1'. Your response was that there should only ever be one record. But, that doesn't mean that record will have an id of 1. Since it is an auto-increment value, the first record would normally have an id of 1 if not specified in the INSERT statement. But, that id could have been specifically set to another value in the INSERT statement, changed later, or if you deleted the first record and created a new one (which could happen while testing/debugging) the id could be anything. So, to answer your question in #10 - which is the same question you asked in #1 and #3, you can use ON DUPLICATE KEY UPDATE using any field as a unique key as long as you include the value of that field in the query and the value is a duplicate of an existing record. Changing from id to company_name makes no difference.
  8. So, you are now apparently using a download script and not "opening" the files. That script likely has the 'name' of the download hard-coded. You would need to show us the code.
  9. @bluefrog: When researching a function you have never used before, here are some suggestions for a beginner: 1) Read through the entire manual page (at least everything before the user contributed notes). If something doesn't make sense to you at first, continue till the end of the content for that function. Then re-read to see if those sections now make sense to you. 2. Pay special attention to the examples. Find one that is close to what you want to accomplish and do it exactly as it is shown. 3. Take the example and make small modifications to change it to what you need. After each modification, run it and ensure the change is working as you expect. If there is a problem, review your code to see what the problem was and fix it. If you can't figure it out at that point, then post what you have to this forum and explain what you are trying to achieve, what you have done so far, and what the problems are that you are facing.
  10. No one is suggesting to use another table - those were examples. Did you even read ginerjm's response? How do you know that there is a HTTP_CACHE_CONTROL value? You need to add code for debugging purposes. <?php if(!isset($_SERVER['HTTP_CACHE_CONTROL'])) { echo "HTTP_CACHE_CONTROL doesn't exist"; } elseif($_SERVER['HTTP_CACHE_CONTROL'] != 'max-age=0') { echo "HTTP_CACHE_CONTROL doesn't equal 'max-age=0'. It is '{$_SERVER['HTTP_CACHE_CONTROL']}'."; } else { $db = JFactory::getDBO(); if(!$db) { echo "Unable to create DB reference"; } elseif(!$details->id) { echo "Details id does not exist."; } else { $query = "UPDATE __hdflv_upload SET times_viewed=1+times_viewed WHERE id={$details->id}"; $db->setQuery($query); if(!$db->query()) { echo "Error executing query. Follow Joomla documentation to output the error."; } else { echo "Success"; } } } ?>
  11. @Sandeep590, you state that these could be any type of file. If that is true, then what you are asking cannot be achieved. Only some file types can be opened within a browser. Other file types can be opened by the user's system if they have the corresponding application for the particular file type. But, that is a hit and miss based on the user's browser and the particular file type. Also, Double-click? Don't tell me you double-click on links in a web page.
  12. There is no need to run a SELECT query to get the current count in order to increment it by one before running the UPDATE query. You can do it all within an UPDATE query UPDATE table SET field=field+1 WHERE id=$id
  13. Here's a revision that adds some debugging: <?php if (!$_SERVER['REQUEST_METHOD']=="POST") { echo "Error: No POST data provided"; } elseif(!Input::exists()) { echo "Error: Input does not exist."; } elseif(!Token::check(Input::get('token'))) { echo "Error: Token check failed."; } else { $db = DB::getInstance(); $sql = "UPDATE `guests` SET `admin` = ?, 'adminid' = ?, `tableposition` = ?, `seat` = ? WHERE `id` = ?"; $guestUpdate = $db->query($sql, array( $_POST['admin'], $_POST['adminid'], $_POST['tableposition1'], $_POST['seat1'], $_POST['id1'] )); if(!$guestUpdate) { echo "Error: Guest update failed."; } else { Redirect::to('membertableguests.php'); } } ?>
  14. What, specifically, is not working? Are you getting errors? Are you providing specific values that are returning results you don't expect? If so, what values are being provided, what are the expected results and what are the actual results? EDIT: I see you have multiple if() conditions to determine when to execute the functionality. However, you have no else conditions. Never assume you will get the requisite data. Including else conditions will provide error/debug handling to help identify errors. E.g. if (empty($_POST['position-guests'])) { echo "No post value provided."; } else { // Code to run goes here }
  15. Dates aside, you have an error in the condition $membershipyear = '2016' That should use a double equal sign for comparison. Also, based on what you provided I assume you have a lot of if/elseif statements for all the different permutations: different org size, renewal year, etc. You should not embed costs into code as it makes updates a complicated and potentially error prone process. It would be better to store the rates in the database and have a single function to calculate the renewal cost. For example, you could have a table with the fields: size, renewal year, normal rate, early rate.
  16. Then you are doing it wrong. You stated previously that the value would be "yes" or "no" based on the checked status. That implies a Boolean value. If you are mixing a Boolean and other types of values in the same field it sounds as if the DB schema isn't correct for the intended need
  17. @Andy_Kemp Regarding Jacques1's previous statement: A Boolean is not the string value of "true" or "false". It is a distinct data type just like strings, integers, floats, etc. Depending on the language/context it can be represented in different ways. In PHP, for example, the literal TRUE Boolean value is represented as: $foo = TRUE; //Literal Boolean However, you can also use other values that will be interpreted as true/false within PHP. Basically anything with a non 0, non-empty value would be interpreted as True (http://php.net/manual/en/language.types.boolean.php). In the MySQL there is no literal Boolean field type. There is a Bool field type which is just an alias for a tiny int. The intent is that Booleans are stored as 0/1. In fact, if you use a literal Boolean in the INSERT query it will be stored as 0 or 1. By storing the strings "true"/"false" you would have to add additional/unnecessary logic when using those values, e.g. if($captcha_login_VALUE_FROM_DB=='true') { //do something } Instead, if you just store as a Boolean/Int 'captcha_login' => isset($_POST['captcha_login']) //Will be TRUE or FALSE Then you can use the returned value directly without having to compare to an arbitrary string if($captcha_login_VALUE_FROM_DB) { //do something }
  18. Some tips: 1. Put all your logic (i.e. PHP code) at the top of the script. Use it to assign dynamic content to variables. Then create the output (i.e. HTML) at the bottom of the script using just PHP echo statements for the content created within PHP. This separates the logic from the presentation. As you build more complicated applications you will completely separate the logic and presentation into separate files. but, for now, go ahead and use a single script. 2. mysql_fetch_row() will return an array into $row, but then you are testing the value against a string. They will never compare. Plus, you are returning id and race, but only looking for one value apparently. Just pull the data you need. 3. Instead of multiple if/elseif statements, use a switch() statement 4. There is no else condition. Perhaps there are no records where a value would not equal one of those options, but it is a bad design. Code should never 'assume'. Create conditions to handle unintended scenarios. 5. The three conditions in your if/elseif statements should only define what is different - in this case just the src for the image tag. Right now, it is fairly simple, but since each condition will output an image, that part should not be included in the condition statements. As the output of such conditions gets more complicated it becomes all too easy to introduce bugs. For example, if you want to change the border of the image to 1 you would have to change it in three places instead of just one. 6. Use PDO or mysqli for database operations. mysql_ has been deprecated for years. 7. If the select statement will take a user defined parameter for the id, you should be using prepared statements Not tested <?php //Set the race ID to be queried //Can be user supplied via $_GET/$_POST $raceID = '1101'; //creating a connection with the database include_once 'dbconnectgs.php'; //Replace the contents of 'dbconnectgs.php' with the following // - using appropriate values for host, database bname, username & password ## $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password'); ## $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ## $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); //Create & run prepared statement $query = "SELECT race FROM siege_locations WHERE id=:id LIMIT 1"; $stmt = $db->prepare($query); $stmt->execute(array(':id' => $raceID)); //Get the race from the query results $row = $stmt->fetchAll(PDO::FETCH_ASSOC); $race = $row['race']; //Determine correct image name switch($race) { case 'ELYOS': $imgName = "elyos.png"; break; case 'ASMODIANS': $imgName = "asmodian.png"; break; case 'BALAUR': $imgName = "balaur.png"; break; default: $imgName = "unknown.png"; } //Define the full IMG tag one with just the variable image name $raceImage = "<img src=\"http://someaddress.me/sieges/img/fortezze/{$imgName}\" border=0>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="styles/eye.css"> </head> <body> <div id ="Divine"> <?php echo $raceImage; ?> </div> </body> </html>
  19. Ok. So, did you have a problem or a question? All you did was state what you have done but not provided anything about any errors or what you want to do differently.
  20. Thanks Barand, Unfortunately, in trying to take out some of the other complexities in order to focus on the specific problem I was facing, I ended up removing an aspect that makes that approach invalid. In my actual data there are hundreds of thousands of data and it was difficult to validate results. So, I created a small test bed of data to test the query using just "Open" and "Closed". My intent was to change it to status IN (list of status ids) once I found a solution. In my actual data there are many different statuses that can represent "Open" or "Closed". A project can change from one Open status to another Open status - the same holds true for Closed statuses. Because of this, getting the 'difference' between "Open" and "Closed" statuses will not work. This will not be used often. At this point, I'm going to use the query I started with that gets me the value for a single point in time and run it in a loop to get the value for all the periods in the report range. As long as the time is somewhat reasonable it will get me to a viable solution for now. I may also consider caching, but the intent is that the report can be run with many different options.
  21. As someone who is responsible for hiring people, I will give you my honest feedback. As a professional, I know that I am not supposed to take into account any disabilities which can be addressed through reasonable accommodations. But, there are some issues with that: What is "reasonable". As the others have stated, much of our communication is via text - but not all of it. What about conference calls where employees talk through issues? Would it be reasonable to have everyone "talk" through text? There may be utilities to do speech-to-text, but on a conference call I suspect they may have problems (people taking over each other, background noise, etc.). And, as a manager, I know it would require more work of me to have to write out everything I need to communicate (stopping by to ask a question, weekly status meetings, etc.). That brings me to the most important factor . . . Even though a manager may consciously see the candidate and understand that the are "reasonable accommodations" that can be made, his subconscious will be thinking about the difficulties that have to be overcome and how it would be "easier" to hire someone else. People don't like discomfort and having to deal with situations they have never dealt with (with the inherent unknowns) is uncomfortable. The manager will ultimately be responsible for the output of the people they hire. So, I agree with Barand and gizmola: 1) A public sector job would probably be less of a challenge due to their hiring practices 2) Having a stellar history/examples of work will help alleviate any hiring manager's possible hesitation
  22. I got it! I made the query a sub-query with the @open_count calculation as part of the outer query (like you had it). Not sure why it wasn't calculating correctly as a single query. I still have more work to do as there are more complicated conditions than what I posted, but I'm pretty comfortable I can handle those. Here is the working query, but if you have any suggestions for improvement I would welcome them -- Calculate initial open count SET @open_count = ( SELECT COUNT(*) FROM projects JOIN ( SELECT project_id, MAX(change_date) as last_date FROM `project_status` WHERE change_date < '2015-01-01' GROUP BY project_id ) AS last_status ON projects.project_id = last_status.project_id JOIN project_status ON last_status.project_id = project_status.project_id AND last_status.last_date = project_status.change_date WHERE project_status.status = 'Open' ); -- Query the monthly changes in open count and apply to @open_count SELECT yearNum, monthName, @open_count := @open_count + openChange as open_at_end FROM ( SELECT MONTH(change_date) as monthNum, MONTHNAME(change_date) AS monthName, YEAR(change_date) as yearNum, SUM(status='Open') - SUM(status='Closed') as openChange FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ) as periodTotals ORDER BY yearNum, monthNum
  23. @Barand, I was waiting for you to respond What you supplied works perfectly for the specific sample data I provided. But, when I add some more realistic data (data that existed prior to January) it is not giving me the expected values. At the bottom I have provided some updated sample data. That data should provide the following output: January: 5 Feb: 4 March: 3 Using your query above I have made some progress and am very close, but there is one problem I am facing. I created the following query which correctly provides the change in open count each month: SELECT MONTHNAME(change_date) AS monthname, -- @open_count := @open_count + SUM(status='Open') - SUM(status='Closed') AS open_at_end FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ORDER BY YEAR(change_date), MONTH(change_date) Result: Jan: 3 Feb: -1 Mar: -1 So, the only thing missing is that it needs the starting value at the beginning of January and apply those changes to the running value for each month (which is what that commented line is for). So, I used the query I first provided to calculate and set that starting value and assign it to @open_count and it is being set correctly (2 with the new data). So, when I uncomment that line above I expect that it will return: January will be (2 + 3) 5, Feb will be (5 - 1) 4, March will be (4 - 1) 3. But, instead I am getting 5, 1, 1. Here is the same query, but I have hard coded the initial @open_count to 2 instead of providing the longer query above. SET @open_count = 2; SELECT MONTHNAME(change_date) AS monthname, @open_count := @open_count + SUM(status='Open') - SUM(status='Closed') AS open_at_end FROM project_status WHERE DATE(change_date) BETWEEN '2015-01-01' AND '2015-03-31' GROUP BY YEAR(change_date), MONTH(change_date) ORDER BY YEAR(change_date), MONTH(change_date) Here is the new sample data CREATE TABLE `projects` ( `project_id` int(11) NOT NULL auto_increment, `name` varchar(32) collate latin1_general_ci NOT NULL, PRIMARY KEY (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ; INSERT INTO `projects` VALUES (1, 'Project A'); INSERT INTO `projects` VALUES (2, 'Project B'); INSERT INTO `projects` VALUES (3, 'Project C'); INSERT INTO `projects` VALUES (4, 'Project D'); INSERT INTO `projects` VALUES (5, 'Project E'); INSERT INTO `projects` VALUES (6, 'Project F'); INSERT INTO `projects` VALUES (7, 'Project G'); INSERT INTO `projects` VALUES (8, 'Project H'); CREATE TABLE `project_status` ( `status_id` int(11) NOT NULL auto_increment, `project_id` int(11) NOT NULL, `status` varchar(16) collate latin1_general_ci default NULL, `change_date` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`status_id`), KEY `project_id` (`project_id`) ) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=16 ; INSERT INTO `project_status` VALUES (1, 1, 'Open', '2015-01-12 17:07:31'); INSERT INTO `project_status` VALUES (2, 1, 'Closed', '2015-03-16 17:07:42'); INSERT INTO `project_status` VALUES (3, 2, 'Open', '2015-01-13 17:09:31'); INSERT INTO `project_status` VALUES (4, 2, 'Closed', '2015-02-10 17:09:36'); INSERT INTO `project_status` VALUES (5, 3, 'Open', '2015-01-13 17:11:39'); INSERT INTO `project_status` VALUES (6, 4, 'Open', '2015-04-14 17:12:25'); INSERT INTO `project_status` VALUES (8, 5, 'Open', '2015-02-03 12:48:09'); INSERT INTO `project_status` VALUES (9, 5, 'Closed', '2015-02-11 12:48:23'); INSERT INTO `project_status` VALUES (10, 5, 'Open', '2015-02-25 12:48:39'); INSERT INTO `project_status` VALUES (11, 6, 'Open', '2014-12-17 13:46:12'); INSERT INTO `project_status` VALUES (12, 7, 'Open', '2014-11-11 13:46:31'); INSERT INTO `project_status` VALUES (13, 7, 'Closed', '2014-12-16 13:46:48'); INSERT INTO `project_status` VALUES (14, 8, 'Open', '2014-12-17 13:47:01'); INSERT INTO `project_status` VALUES (15, 8, 'Closed', '2015-02-10 13:47:14');
  24. I *think* I see what you are doing there. You have separate queries to get the counts of different parameters and UNION them together. Each query appears to have logic to get the COUNT() for a particular parameter in each month/year. Maybe I oversimplified my sample data. For example, I could have a project that is 'Open' on Dec. 5, gets changed to a status of 'Closed' on Dec. 5, then gets moved back to 'Open" on Dec. 10. When I get the number of projects that are open at the end of December, I need that project to count only once even though there are two status records in December with a a value of 'Open'. I'll continue to review what you've posted to see if there is some solution I am not seeing.
×
×
  • 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.