Jump to content

benjam

Members
  • Posts

    43
  • Joined

  • Last visited

Everything posted by benjam

  1. They do have their place. I've used them on a few occasions.
  2. Thanks Abra, that's what I was looking for. And to all others, I am aware of arrays and understand they are easier/better in this particular situation, but the solution I was looking for is valid in other situations as well, not just looping over incremented variables.
  3. How can I go about incrementing a variable name without using interim variables? Example: I have several variables called $foo_0, $foo_1, $foo_2, $foo_3, etc. and I would like to access them in a loop. for ($i = 0; $i < $count; ++$i) { echo $foo_{$i}; // does not work, but would be the most elegant solution $name = 'foo_'.$i; echo ${$name}; // works but is not very elegant } Is the second solution the only way? Or is there a variation of the first method that I'm just not seeing?
  4. ummm... nm, apparently that query did work I went in to look at some things, and noticed the states listed were ids, and not abbrs anymore. neat.
  5. I have a couple tables with the following (trimmed) schemas reps ----------- id (PK) name state (contains 2 char state abbr) states ---------- id (PK) name abbr (contains 2 char state abbr) What I'd like to do, is to read the reps.state value, and replace it with the state.id value... something like this: UPDATE reps SET reps.state = ( SELECT states.id FROM states WHERE states.abbr = reps.state ) ; I know that query won't work, but that should give you the idea of what I'm looking for. Any ideas? I could loop through with PHP, but I was looking for a more elegant MySQL only method.
  6. I am currently having a very odd issue. When I try to login to mysql via command line with the following: $> mysql -u 'username' -p'password' (I also tried with -p 'password' and -p='password') ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES) if I log in with: $> mysql -u 'username' -p Enter password: ******** it logs me in just fine. Why would the two methods be different? And how can I fix it? (I need to be able to log in completely via command line because I use a batch file to run some things)
  7. Well, the problem is no longer an issue, as it was 'fixed' by switching the data type from FLOAT to DEC. Now I just want to satiate my curiosity, and for future reference. But here is some sample data, the query, and some sample return data: (Please note that bsyn and tsyn are basically the same tables with some differences in the Z values) CREATE TABLE bsyn ( X FLOAT NULL, Y FLOAT NULL, Z FLOAT NULL, ) ; INSERT INTO bsyn VALUES ('455526.272000','1644214.016000','5613.504598') , ('455529.088000','1644226.176000','5613.766831') , ('455531.904000','1644238.208000','5614.029063') , ('455534.720000','1644250.496000','5614.291295') , ('455537.536000','1644262.656000','5614.553528') , ('455540.352000','1644274.816000','5614.815760') , ('455543.168000','1644286.976000','5615.077992') , ('455545.984000','1644299.264000','5615.340224') ; SELECT bsyn.X , bsyn.Y , bsyn.Z AS z1 , tsyn.Z AS z2 , bsyn.Z - tsyn.Z AS diff FROM bsyn , tsyn WHERE bsyn.X = tsyn.X AND bsyn.Y = tsyn.Y ; +--------+--------------+---------+---------+------------------+ | x | y | z1 | z2 | diff | +--------+--------------+---------+---------+------------------+ | 456187 | 1.64708e+006 | 5797.5 | 5644 | 153.50244140625 | | 456190 | 1.64709e+006 | 5798.31 | 5645.12 | 153.1904296875 | | 456193 | 1.6471e+006 | 5799.12 | 5646.24 | 152.8779296875 | | 456196 | 1.64711e+006 | 5800 | 5647.37 | 152.63623046875 | | 456199 | 1.64712e+006 | 5800.88 | 5648.49 | 152.39501953125 | | 456201 | 1.64714e+006 | 5801.76 | 5649.61 | 152.15283203125 | | 456204 | 1.64715e+006 | 5802.64 | 5650.73 | 151.9111328125 | | 456207 | 1.64716e+006 | 5803.52 | 5651.85 | 151.6689453125 | | 456210 | 1.64717e+006 | 5804.4 | 5652.97 | 151.42724609375 | | 456213 | 1.64719e+006 | 5805.28 | 5654.09 | 151.185546875 | | 456216 | 1.6472e+006 | 5806.16 | 5655.21 | 150.94384765625 | | 456218 | 1.64721e+006 | 5807.04 | 5656.33 | 150.7021484375 | +--------+--------------+---------+---------+------------------+
  8. Outputting to command line. The data gets inserted in, then some simple arithmetic when it gets pulled out. I apologize, I don't have any test data for you to look at. But apparently, my wife (the person with the problem), switched the data type to DEC from FLOAT and it worked fine, giving all returns in decimal notation. Why would that be, I thought they were the same?
  9. I am pulling data from a table and want the numbers to be output in decimal notation, but MySQL keeps outputting the numbers in scientific notation. Is there a way (and I'm sure it's a simple one) to force MySQL to use decimal notation instead?
  10. I have a user who is using a script I edit, and this user is having troubles with php files being downloaded instead of parsed and output to the browser screen. I have opened the page in several browsers, so it is not a browser problem, but it is very odd because some files are parsed as normal, and then others are not. And it's not file specific, meaning that at one moment one file parses fine and another gets downloaded, and then at another time, the problem is the reverse. I have many other users who use this same script and have no problems with the page being downloaded, so it must be box specific, but I have no idea what might be causing this extremely odd error. Any thoughts? The site in question is: http://www.re-al-schule.de/webchess-new/webchess/ there is a user in the system with login info: test - test And another site where the script works as it should: http://www.iohelix.net/webchess/ there is also a user in this system with login info: test - test the error occurs when a user tries to make a move, and again when the user tries to return to the menu page.
  11. I have a couple of scripts where one is an AJAX socket 'client' and the other is a socket server, both in PHP. The nature of the AJAX beast is such that, it must reconnect every time it sends data to or from the socket server. If any data comes in while this reconnect is taking place, that data is lost to the AJAX socket client. I have found a way around this using buffers: the incoming data gets stored in a buffer, if the client is there, the buffer is sent and cleared. If the client is not there, the buffer continues to be saved until the client returns, at which time the buffer is sent and the process repeats. The problem I am having is, if the client disconnects, for whatever reason (but to return later), the server does not realize the client has disconnected until after it has sent the next line and loops back to try to read from the disconnected client, which fails, and it then disconnects the client from the local side, and begins to store the buffer contents. But the first line is already deleted from the buffer. I have tried testing FALSE against socket_read($client_sock, 0), socket_write($client_sock, ''), socket_getpeername($client_sock, $null), and all with no luck. The only way the server seems to notice that the client has disconnected is when it tries to read more than a zero length data stream (which I cannot test against, for there may be other clients sending data through those socket_reads, in which case, the valid incoming data will be lost). Does anybody have any suggestions on how I might test for a valid connection before sending my buffer contents, one which does not disrupt any other clients, and works every time? Thanks simple code samples avail upon request
  12. I'm an idiot. The query above IS working correctly. It was the subsequent queries that were pulling the bad information. I was not testing the status flag correctly in the query that came after the above query. Crisis averted, all is well. Sorry to waste your time.
  13. I have a simple JOIN query that is pulling (at least one, maybe more) results that are incorrect. I have played around with the query and cannot seem to figure out why it is pulling these incorrect values. Here is my query: SELECT AUEG.appId FROM AppUserGlue AS AUEG LEFT JOIN User AS UE ON UE.userId = AUEG.userId WHERE UE.clientId = '{$clientId}' AND AUEG.createDate BETWEEN '{$periodStart}' AND '{$periodEnd}' AND AUEG.status = '".APP_USER_GLUE_ACTIVE."' ORDER BY AUEG.appId APP_USER_GLUE_ACTIVE = 1 APP_USER_GLUE_INACTIVE = 2 the $periods are unix timestamps and the $clientId is INT here is some sample data: AUEG appUserGlueId appId userId createDate status 374 495 20 1170794281 2 (inactive) 375 495 126 1170795497 1 376 823 12 1170791235 1 UE userId clientId 20 31 126 56 12 31 When I run the query with the clientId of 31 (and a period that is guaranteed to return all entries), it returns BOTH the appIds of 495 and 823 when it should only return one appId: 823, because the first one (495) doesn't have an active status flag to be pulled. I modified the query to return everything form both tables and it seems to be pulling the correct user data, but it shouldn't. i.e. - it pulls userId 20 and 12, although the appId related to userId 20 has an inactive status flag. I also tried moving the conditional statement (AND UE.clientId = '{$clientId}') into the ON clause with disasterous results (it returned even more incorrect values). I can't seem to figure out how to word this query to get it to function the way I intend it to. Thanks for any help anybody can offer.
  14. Thanks, works like a charm. So for those of you following this, the query is: [code]SELECT A.name   , A.id   , SUM(IF(C.value != 0, 1, 0)) AS filledValues   , COUNT(C.id) AS totalValues FROM TableC AS C   LEFT JOIN TableB AS B     ON B.id = C.tableB_id   LEFT JOIN TableA AS A     ON A.id = B.tableA_id GROUP BY A.id ORDER BY A.name[/code] One thing that didn't make sense, when I ran the query with the totalValues being counted as COUNT(C.*) it returns an error at that location.  But COUNT(C.id) is fine, and works as expected. What might be the reason for this?
  15. But I don't want the sum, unless I am misunderstanding you... Could you give me more details please? I want the number of rows that have a value not equal to zero that are related to the TableA entry as well as the total number of rows that are related to the TableA entry. Is this what you were thinking?
  16. And I'm going for speed here, this is a stats query that will be run by an over zealous marketing guy in our office at least once every 15 minutes on a database with hundreds of thousands of entries (in TableC, TableA might only have 20 or so).  So if running this in PHP will be faster, then I'll do it that way, I've just always heard that MySQL is faster than PHP when it comes to counting things. Also, if you have any suggestions on indexes that would speed up this query (if it's determined that that method is faster), please let me know. And there is an error in the query, it should be: [code]SELECT A.name   , A.id   , COUNT(C.value != 0) AS filledValues      -- i know this isn't legal, but you get the idea   , COUNT(C.*) AS totalValues FROM TableC AS C   LEFT JOIN TableB AS B     ON B.id = C.tableB_id    -- this bit was changed from above (C relates to B, not vice versa)   LEFT JOIN TableA AS A     ON A.id = B.tableA_id GROUP BY A.id ORDER BY A.name[/code]
  17. I would like to pull data from three tables (one is basically a linking table) where the query counts the number of instances of a certain value as well as the total number of rows. Something like this: [code]SELECT A.name   , A.id   , COUNT(C.value != 0) AS filledValues      -- i know this isn't legal, but you get the idea   , COUNT(C.*) AS totalValues FROM TableC AS C   LEFT JOIN TableB AS B     ON B.tableC_id = C.id   LEFT JOIN TableA AS A     ON A.id = B.tableA_id GROUP BY A.id ORDER BY A.name[/code] I know that query will not work, but I was hard pressed to find an easier way to explain what I wanted as output. I want a list of all entries in table A with counts of various bits in table C, whether they are zero or not. I also want the count of entries in C that have no related entries in B or A (hence pulling from that table first). Does anybody have any suggestions?  Or is there some simple thing that I am just missing? Or do I just need to loop through it in PHP and count my values that way? Thanks in Advance
  18. I am still having problems with this and am wondering if anybody else might have anything to say about it... Any errors that may pop up when using IIS that do not occur when using Apache?
  19. it won't be until tomorrow, i don't have the internet at home
  20. well, my user said they reverted back to a previous version, made an adjustment in the php.ini file and got it to work fine, but then brought it back to the current version, tried to make a few moves and it hung again, but this time, it made the move, whereas last time, it did not. So, he'll get me his php.ini and phpinfo() output tonight and I'll post it here (sensitive info removed of course). Here is what he told me though: I believe the issue is with IIS 6 and PHP.  The reason I believe this is due to the following test: 1.  Went back to version 2.0a 2.  Everything worked fine for a few moves, then the system would hang, time out, but it would make the move when I logged back into the system and checked. 3.  Found a new error in the Event log:  Application  blah blah blah (I'm at work and don't have it memorised) 4.  Changed a setting in the php.ini file 5.  Logged back onto the system, and could then play a complete chess game with no hang ups on version 2.0a.  I was excited. 6.  Installed version 2.0b3 (the latest), made my first move, logged out and made the second move, and the system hung, BUT it made the move whereas befoe it would not make the move. p.s. -  We both thank you for your help with this.
  21. Thanks for your help... and I have thought about AJAX for this, but my hosting co still uses Apache 1.3 so it would be no good for me. Anywho... The user says they install the script, register a user, register another user, invite the other user to a game, begin the game, make the first move, make another move as the other player, request an undo, log in as the other player, accept the undo, return as original player, try to make a move and the game hangs. Or something similar. There is a debug function you can turn on through the config file at the end of the file, set DEBUG to true and it will output a ton of stuff.  (May cause problems with headers already being sent, depending on your setup) And I'll see if I can get his php.ini file from him for you to look at.
  22. Well, unless you want the entire chess script, I'm not going to do that.  It's rather large and I'm not exactly sure where the error is occuring as I do not use IIS and cannot debug efficiently enough to figure out where that is. But my question was not 'What's wrong with my code', but What may be different between IIS and Apache that may be causing problems?  No code is required for this question. But if you must: http://www.iohelix.com/misc/webchess2b.zip and the error is occuring somewhere after making a move and then requesting an undo of that move. (chess.php or one of it's includes)
  23. I have been editing a chess script and a user of the script has run into problems with his installation. When asked about his server setup it was discovered that he is using IIS on Server 2003. The errors seem to be happening when data is being sent through POST and I am unable to reproduce any errors on my Apache-based server. Is there anything that may be different when running PHP on IIS from Apache that I need to know about to get this problem fixed? Thanks.
×
×
  • 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.