Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. I understand what you are saying Ken, but it doesn't answer my question.  It's not necessary to test for setness before making a comparison with == under usual circumstances, as null != 'yes'. Try the following test script [code=php:0]<?php if ($a == 'yes') print "Unset variable is == to string constant\n"; ?>[/code]
  2. Corbin, the point of my post is that they are not set to 'yes', but the expressions are still evaluating to true.  In fact, they are not set to any value. If anyone can explain how this could happen, I am very interested to hear :)
  3. What is the reason that you can't use a temporary table?  What fenway means is something like this (my syntax may not be correct for mysql): [code=php:0]CREATE TEMP TABLE student_max_test_date AS SELECT studentID, MAX(test_date) AS test_date FROM reading_fluency WHERE test_date > '2006-09-01' GROUP BY studentID;[/code] [code=php:0]SELECT studentID, test_date, score FROM reading_fluency JOIN student_max_test_date USING (studentID, test_date)[/code] There's no need for the awkward construct for score here, as the max test_date has already been found.  Then a simple join gets you the scores that match those max test_dates.
  4. I have a very odd situation occurring in my code.  The entire app is around 50k LOC and uses postgres. The situation only occurs when processing large amounts of data. The code with unusual behaviour looks like this: [code=php:0]if($_REQUEST['exceltype'] == 'yes'){[/code] Now, $_REQUEST['exceltype'] is not set, as verified by var_dump($_REQUEST) inside this if statement.  BUT, the if statement succeeds!  The if statement fails if I use === instead of ==. Is there any setting or circumstance in php which could cause unset values to evaluate as equal (in the == sense) to a string? More information:  The code is running on the following system: Server: Apache/1.3.33 (Debian GNU/Linux) mod_gzip/1.3.26.1a PHP/4.3.10-18 mod_auth_pam/1.1.1 mod_ssl/2.8.22 OpenSSL/0.9.7e mod_perl/1.29 mod_choke/0.06
  5. Oops, you can't "update from" in mysql.  It doesn't support the syntax. Instead you should be able to do [code=php:0]UPDATE PRODUCTS SET onhand = (SELECT onhand FROM INVENTORY WHERE INVENTORY.sku = PRODUCTS.sku)[/code]
  6. btherl

    cron vs httpd

    Yes it's possible to run apache as your username.  I think it's more a question of what the admins will allow, since you're using a managed dedicated server (I assume that's what you're using?) You might want to ask them about enabling suexec for some scripts only (in a particular subdirectory holding your cron jobs, for example) but using the apache module for your regular php.
  7. As a rule of thumb, a syntax error on line X really means "Anywhere before line X".  And the easiest way to fix it is to use an editor which has php syntax highlighting.
  8. btherl

    cron vs httpd

    It's not impossible, but don't argue with them.. just wait for the admin's response. Regarding making requests via the webserver, the scripts will take the same resources either way.  The only problem would be the default timeout in php.  You may be able to modify this using http://sg.php.net/manual/en/function.set-time-limit.php Note the comment on that page that if you are in safe mode, you can't modify the time limit that way.  Instead you'll have to set max_execution_time in php.ini I don't think chown() will work, because you can't "give away" files in most versions of unix.  You can set permissions, but that's a huge hassle.
  9. Hmm.. I can offer a low-tech solution.  Select all the test results and [code=php:0]ORDER BY studentID, test_date DESC[/code].  Then use a foreach loop to pick the first entry for each student.  You can also order it ASC and pick the last entry (that can be convenient, since you just keep assigning.. and the most recent assignment for that student is their latest test score). I'm very surprised that the max ends up being for all students.  I guess it's a side-effect of how assignment is implemented. Anyway, my answer to your original question is "No, I can't think of how to do this without subqueries".  It's breaking the rules to aggregate one column and then use that result during the aggregation of another column.
  10. From http://dev.mysql.com/doc/refman/5.0/en/internal-locking.html [quote]InnoDB uses row locks and BDB uses page locks. For these two storage engines, deadlocks are possible because they automatically acquire locks during the processing of SQL statements, not at the start of the transaction.[/quote] Yep, myisam doesn't have row-level locking.  You'll need to use innoDB (or switch to postgresql :P )
  11. My gut feeling is that you have an include loop.  If you aren't already, try using include_once() instead of include(). Another idea is to print something out at the start of each of your files.  Then you can see in what order which file is run.  It basically gives you a trace of what was included where.  Alternatively you can put this data into a global array, and print it out later.
  12. Collation order defines the order in which data is sorted, but not the format in which it's stored.  That's a question of "character set" and "character encoding", not "collation order".  I can't help you with that in mysql, but that should point you in the right direction. One safe but inefficient option is to encode your data, for example with urlencode.  That will armor it so it can be stored in virtually any character set.  But you will have to urldecode it every time you fetch it.
  13. Try this: [code=php:0]UPDATE PRODUCTS SET onhand = INVENTORY.onhand FROM INVENTORY WHERE INVENTORY.sku = PRODUCTS.sku[/code] You don't need to join in this case.  What you're doing is more like "SELECT INVENTORY.onhand FROM INVENTORY WHERE INVENTORY.sku = PRODUCTS.sku" for each row of PRODUCTS.
  14. Aha, I get it.  You're welcome :) If you want to include the dropped user, use LEFT JOIN instead of JOIN.  That will include rows which exist in the left table but not the right table.  The right table's columns will be filled with nulls for that row.
  15. A good first step is to check all your mysql_() functions for errors, like this: [code=php:0]mysql_query("select * from news") or die("Error: " . mysql_error());[/code] Add something similar to mysql_connect() and mysql_select_db()
  16. Or if you really despise $_POST['submit'] and never want to see its face again, [code=php:0]unset($_POST['submit']);[/code]
  17. Some possible causes 1. the php.ini you are looking at is not being used 2. the php.ini you are looking at is being used, but the extension path is not being changed due to some syntax or permission problem Some possible solutions 1. Edit the php.ini that IS being used :) 2. Fix whatever error is in the php.ini 3. Or, if neither of the above were the causes, move all your extensions (or copy them) to where PHP expects them to be.
  18. The path is relative to the included file, not the including file.  That means you can do [code=php:0]include('../header.php');[/code] to include one level up. I think your best bet is a little function to walk up the path and try including files for you.  That function will need to be in a fixed location so it can be included before the other including takes place.
  19. btherl

    cron vs httpd

    Do you login as scott to edit your cron jobs?  Ask your hosting provider if you can login as nobody so you can edit nobody's crontab (which will run as nobody). If that's not possible, just describe your problem and ask them how you can run cron jobs as nobody.  You could also run them as root, but I wouldn't recommend it unless you're experienced in unix.  You could easily trash your server with a typo if you run them as root. This is a good time to remind you to make regular backups :)
  20. It could be failing due to the working directory, particularly if you use relative paths to include other files.  It also could be failing due to permission problems. For this kind of "blind" debugging, you can try logging debugging output to a file.  A good start is to have a line at the very top of your script like [code=php:0]file_put_contents('/tmp/I_have_run.' . posix_getpid(), date('[Y-m-d H:i:s] Script executed';[/code] That'll create a file each time your script runs.  If the file isn't created, that means the script is not even starting.  Or the script is not allowed to write to /tmp (quite possible if it's running under the web browser).  Try putting that both before and after any include() or require() you may have.
  21. Hmm.. assuming the format of shoutbox.txt is fixed, you could do [code=php:0]$shoutbox_lines = file('shoutbox.txt') or die('Couldn't open shoutbox.txt'); # This part depends on order of entries.. I am assuming the latest entry goes at the bottom, and top-most entry is deleted. unset($shoutbox_lines[1]); # Delete the second line (numbering starts at 0 $shoutbox_lines[] = $new_line; file_put_contents('shoutbox.txt', join("\n", $shoutbox_lines)) or die('Couldn't write new shoutbox.txt');[/code]
  22. If you don't check for errors then you won't get any :) Add [code=php:0] or die("Error: " . mysql_error());[/code] after each mysql_query(), and it'll tell you if those queries are failing. eg [code=php:0]mysql_query("INSERT INTO staff VALUES ('$username','Admin','0')") or die("Error: " . mysql_error());[/code]
  23. Sorry, I messed up the syntax :) What do you mean by "it dropped one user"?
  24. Yep, it's your IIS configuration.  I can't help you more than that since I'm an Apache user.  Basically you need to tell IIS that files that end in ".php" should be processed by php, instead of served as files.
  25. Instead of just adding new entries to shoutbox.txt, you can read in shoutbox.txt, delete the oldest entry, add the newest entry and rewrite it.  Is this the kind of solution you are looking for? The "sophisticated" way would be to use mysql, but it's not necessary for something so simple.
×
×
  • 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.