Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Opps, I misread your problem to be that you didn't want the selected name to be included. Is the data you posted correct? Carl has the same sid as the others. There's nothing in what you posted that would exclude carl form the result set.
  2. Add the following - AND parent.name != child.name
  3. if(isset($_POST['submit'])) <----- that will never be set because your form does not have a field with a name="submit" attribute.
  4. That's why someone suggested -
  5. What's wrong with using $_POST['variables'] directly in your code? They are perfectly fine variables. If you want an $item array that is a copy of the $_POST array - $item = $_POST; If you want to populate scaler program variables from the $_POST elements, you can use extract Use EXTR_PREFIX_ALL as the second parameter and use a unique prefix to insure that hackers cannot overwrite any of your existing program variables.
  6. Since you didn't answer the questions or post the code we asked for, I looked back through your threads and found some likely code to test with. Using an UPDATE query for each player, in a loop, I got similar results. ~3.7 seconds for 200 rows (with the update query commented out, it took ~30ms.) I also tried a mysqli prepared statement for the UPDATE query, with little or no speed difference (at most it was .1 second faster.) I also tried the UPDATE query with and without the LOW_PRIORITY keyword (no measurable speed difference.) Then I tried a mysqli prepared REPLACE query in a loop (no measurable speed difference.) I suspect that most of the time taken by this is for the communications between php/mysql for each query or in the case of the prepared query, the time taken to communicate the values to put into the prepared query (I am using the latest php5.3 with the mysqlnd driver on a Windows development system.) Lastly, I tried a multi-value replace query - REPLACE table_name (columns) VALUES (row data),(row data),(row data),.... This took ~50ms for the 200 rows. This requires that you retrieve all the column values from the existing rows and put them back into the replacement row data. You will also need to calculate the hourUpdateTime in your script instead of in the query. This is the code I tested with - <?php $st = microtime(true); #Players will have to be updated with the team because we have to check for team medic $query = "SELECT players.playerID, players.name, players.injuryTime, players.energy, players.morale, players.confidence, players.fitness, players.hourUpdateTime, players.teamPlayedFor, teams.staff FROM players INNER JOIN teams ON players.teamPlayedFor = teams.teamID WHERE players.hourUpdateTime<'$updateTime'"; #Get all the players of the team $players = mysql_query($query); if(!mysql_num_rows($players)){ echo "No matching rows"; } else { while($player = mysql_fetch_assoc($players)) { #Go through all the players of the team extract($player,EXTR_PREFIX_ALL,'r'); // $r_playerID, $r_name, $r_injuryTime,... echo $r_name; if($r_staff) echo " - Hey, I've got a coach!"; echo "<br />"; #Energy if($r_energy<1000) $r_energy += mt_rand(1, $r_fitness/100+$energyBonus); #Get some energy back if($r_energy>1000) $r_energy = 1000; #Don't allow energy to go over 1000 #Morale if($r_morale<1000) {$r_morale += mt_rand(1, $r_confidence/100+$moraleBonus); #Get some morale back if it is low } else {$r_morale -= mt_rand(0, 3);} #If morale is high then lose a little #Confidence if($r_confidence<1000) {$r_confidence += mt_rand(0, 3+$confidenceBonus); #Get some confidence back if low } else {$r_confidence -= mt_rand(0, 2);} #If confidence is high then lose a little #Injuries if($r_injuryTime) { $r_injuryTime--; #Take a bit of injury time off $r_injuryTime -= $injuryBonus; #Bonus to healing if($r_injuryTime<0) $r_injuryTime=0; #Can't have a negative number } $r_hourUpdateTime += 3600; // produce 9 replacement values for each query $data[] = array($r_playerID,"'$r_name'",$r_injuryTime,$r_energy,$r_morale,$r_confidence,$r_fitness,$r_hourUpdateTime,$r_teamPlayedFor); } // end of while loop //echo '<pre>',print_r($data,true),'</pre>'; $terms = ''; foreach($data as $arr){ $terms .= "(" . implode(",",$arr) . "),"; } $terms = rtrim($terms,','); $query = "REPLACE players (playerID,name,injuryTime,energy,morale,confidence,fitness,hourUpdateTime,teamPlayedFor) VALUES $terms"; //echo "---$query---"; if(!mysql_query($query)){ echo $mysql_error(); } else { echo "done"; } } $et = microtime(true); $time = $et-$st; echo "Time; $time";
  7. Did you look at the paths you have in your code, compared with where you are saving the curl results?
  8. What does the forum section you posted this in (Javascript help), the title of your post (illegal variable _files or _env or _get or _post or _cookie or _server or _sessi), the problem (this worked for awhile, now it doesn't work), and the php code have to do with each other? Do you have an actual programming problem, programming error, or programming question that you need help with?
  9. Are you sure you only want to check the box is there are errors - isset($_POST[errors])? Have you checked the two $_POST values that your logic is testing so that you know they have values that would cause your code to do what you expect?
  10. Perhaps if you post an example of the data you have and the result you want, someone could help. In looking at that code, I doubt anyone here can tell what it is you are trying to accomplish. You would never select all your data, then as you loop through each row, reselect some of the same data again. If the three columns - serveradded, servupdate, and newuser are actually types/categories, why don't you have one column named `type` or `category` that holds either 'serveradded', 'servupdate', or 'newuser' directly as strings or as values/enums to indicate the type for that row?
  11. el.name = 'txtRow[' + iteration + ']';
  12. To wedge a large file, piece by piece, into a column, you would need to concatenate each successive piece with the existing content already stored in the column - http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_concat You would need to perform the compliment of that process every time you try to retrieve the file.
  13. I recommend that you use an array for the form field name, with the 1,2,3,... as the array index txtRow[1], txtRow[2], txtRow[3]. Then your php code will be able to iterate over the data.
  14. It would probably help at this point to post your code so that someone could see what it might be doing that is using up available memory and not releasing it at the point where you are reading in the uploaded file.
  15. The last logic you posted is nonsense. You will get the "failed to connect to database" message when you have connected to the database server and when you successfully selected the database. Why are you randomly changing the logic in your code. The logic in the first post in this thread would have told you if and why the database connection failed. The query is actually succeeding, but the logic you have around the query statement is still not what Pikachu2000 already told you how to fix.
  16. Define: it doesn't work? There could be a dozen different things for the code fragments you posted that could have stopped as the result of moving between different server configurations. Exactly what symptom or error did you see in front of you that leads you to believe - 'it doesn't work'?
  17. Your current error message is?
  18. You are trying to assign (one = sign) a zero to the mysql_num_rows() function. An equal comparison is two == signs.
  19. Here's a method that calculates the sum in real time - http://javascript.internet.com/forms/auto-sum-form-boxes.html
  20. http://www.phpfreaks.com/forums/index.php?topic=95426.0
  21. By setting error_reporting to zero, you are hiding any php errors that would help tell you why your code is not working. By using output buffering and performing a header() redirect, any php errors that would have been reported and displayed on that page will be lost. When developing and debugging php code, you need to have error_reporting set E_ALL and display_errors set to ON and you need to get all output buffering statements out of your code. Edit: If you are going to set the error_reporting/display_errors settings in your script (for debugging purposes), you need to set them immediately after the first opening <?php tag on your main page that is being requested so that any errors in all the code on that page will be reported and displayed. Putting them inside included files won't help if there is a problem including that file.
  22. You are planning on inserting an 800M Byte file(s) into a database? The default maximum size of data that you can transfer in one query (max_allowed_packet) is 1M bytes. Storing files in a database is not a good idea. Php will display the setting (the MB), even if it is not a valid value. Probably because the setting wasn't actually changed or it is being overrode some place else, such as in a .htaccess file or a local php.ini file or there simply isn't any more memory available to allocate. The memory allocation error message implies that the file is being uploaded without error, but that you cannot read it into a variable due to the amount of available memory. You will either need to increase the max memory size, don't attempt to read the file into memory at all, or read the file in chunks using fopen/fread.
  23. Where's your session_start() statement? Also, you need an exit; statement after those header() redirects to prevent the remainder of the code on your 'protected' page from being executed when a hacker ignores the redirect.
  24. A couple of points - Using MB (with the B) on the end of a php.ini setting is invalid. Just use M The memory error implies you are reading the uploaded file into a php variable. Do you need to do that or can you just move the uploaded file to its final location (which occurs through the operating system and does not consume php memory equal to the size of the file)?
  25. Are you sure the problem is the UPDATE queries and not the processing you are doing to produce the values? How are the UPDATE queries being formed? If you are first selecting the data, then UPDATING it, that is generally not necessary, depending on what you are doing. If you want help with a performance problem with your code, you would need to post all the code being executed so that someone could actually see what you are doing and where the possible problems are at. It may very well be that for the number of players, you are already getting the highest throughput and the solution would be to limit or break up the players between multiple servers. Edit: About the only general thing that comes to mind that would speed up executing a number of same queries, with different data values, would be to use prepared queries.
×
×
  • 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.