Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Can you reformat your output a little? I can't tell if you are getting more rows or if you are getting more columns than you expected.
  2. if you're dealing with english data only, you don't even need preg_match, just ctype_alpha() and ctype_alnum()
  3. Try this: system("ls -l /logfiles/a.txt"); fopen("/logfiles/a.txt","w"); Does it show the file you are trying to open? Also, are you using SELinux? Check what's in /etc/selinux/config
  4. Sorry, I don't get what you mean here. In my mind, a function and a series of values (indexed by input variable) are equivalent. My motive is to rank various entities (such as websites, links, search terms) based on various values. At the low end of the scale, differences in rank are very important, but at the high end of the scale (meaning lower ranked), differences in rank are less important. Hence the need for a log like approach to interpreting these ranks. I am also ranking other entities according to counts (eg, times a search term was entered). In this case a logarithmic scale is also useful, but this time because I want the numbers to be manageable. For example, google might be a 9.9 on a scale of 1 to 10, which is easier to understand to the average person than google being a 48375857 on a scale of 1 to 53875936.
  5. Hi! I'm looking for some functions which "look like" log. That is, f(x) should start out increasing fast for x near 0, and then slow down as x increases. If you can provide a class of such functions (mathematical class, not PHP class) then that would be even better I want these to apply to some data points to squash them down into a log like scale. But log often isn't quite the right function, so I want to try some other similar looking functions. The key points for these functions are: - Implementable in PHP - Input domain is integers in {1..INT_MAX}. - Parameters if possible, to affect the shape of the curve in various ways - First derivative starts high but approaches 0 as x increases - Not c*log_b(x), I've tried that
  6. Check here Note the use of the word "positive" Also read this (which explains why rational powers of negative reals are troublesome)
  7. Before fixing the problem, it would be good to verify that it really is a problem Check that rename() returns false (indicating failure to rename). If that's the case, then chocopi's approach should work. If you're ultra paranoid, you may want to make a backup of the file you're deleting, just in case.
  8. Oops.. yes that will make testing difficult Unless you install a develeopment environment like cygwin (or even linux in a virtual server). I'm not 100% sure that cygwin would work for this purpose anyway. Well, you can test the framework on the server, and then introduce the real scripts later.
  9. Aha. So is the problem you are having that the rename() fails when the destination file already exists?
  10. When you fork, you get the pid of your child. And you also get notification via wait() for when the child is finished. If you put a process into the background through exec(), then you won't get notification when it's done. I use this to check if any children have finished (edited a bit for brevity): foreach ($running as $job => $v) { if ($v['pid'] === false) continue; $res = pcntl_waitpid($v['pid'], &$status, WNOHANG); if ($res === -1) { print "Error waiting on children (may be none left)\n"; } elseif ($res === 0) { # Child not exited yet } else { print("$job child {$v['pid']} has exited\n"); } }
  11. So you disguised your stats collector as an swf? If you want to pass the referrer on, you will need to do it yourself.. for example, you can have your php script that generates the actual page pass the referrer to the stats script. If you have access to web server logs, you could also get the referrer from there instead of recording it live. The stats script looks like it was intended to be included rather than run seperately, as that's the only way the referer would be preserved. As for capturing the whole url, I believe it is. It displays the host as the link text, but the full url is linked to.
  12. These lines should be: $email_recipient = $_REQUEST['recipient']; $email_subject = $_REQUEST['subject']; $email_content = "Name: \t{$_POST['name']}\n"; $email_content .= "Email: \t{$_POST['email']}\n"; $email_content .= "Comments: \t{$_POST['comments']}\n"; $email_content .= "IP Address: \t{$_SERVER['REMOTE_ADDR']}\n"; Try that out.. I assume your form uses "method=post" ? $_REQUEST contains everyithing in $_POST, as well as $_GET (and other stuff too)
  13. + is just a shorthand notation. It's not a totally different style. URL decoders should be able to handle both styles.
  14. See this warning here: "If the destination file already exists, it will be overwritten." The default behaviour is to replace the file.
  15. It's likely that register_globals was switched off. Try using these lines instead of what you have there: $require1 = $_REQUEST['name']; $require2 = $_REQUEST['email']; $require3 = $_REQUEST['comments']; If this IS the problem, you will also need to change other places where data comes from the form. Looks like $recipient and $subject will need to be changed as well.
  16. Here's some clarification on the forking process, in case you're not used to such stuff: $pid=pcntl_fork(); if ($pid == -1) { die("Could not fork. Got a knife?\n"); } else if ($pid) { // we are the parent $running[$job]['pid'] = $pid; } else { // we are the child. Do child stuff pcntl_exec('/bin/true'); # Goodbye cruel world }
  17. I don't think php does multithreading, but it does do multi-process. I have written several php daemons which spawn children to do jobs that need to be done simultaneously. You have to be careful, as resources held by the parent will be closed if the child exits cleanly, as the child also believes it holds those resources. The solution here is NOT to exit cleanly. Instead you can exit with this: pcntl_exec('/bin/true'); This will kill your child without closing any resources shared with the parent. My main loop is like this: while (true) { Any kids exited? If no, wait a while and continue the loop Kid has exited! Finish up after child, and fetch a new job of the same type from the appropriate queue pcntl_fork() to start new child Make sure child exits using pcntl_exec(), not exit() } The script ensures there is a child running one job of each type at any time (unless there are no jobs in the queue for that job type, in which case it just waits).
  18. You can't, and I can't imagine why you would want to. The query will not be any faster, and you can always remove the password from the result. You could also list the columns, which gives you self-documenting code.
  19. Oh dear.. "most recent" is a tough one. I think you can do it like this (not tested but it makes sense to me) [/code]SELECT .... , sales_joined.SalesRep as most_recent_sales_rep FROM (SELECT *, count(*) as TotalServices, GROUP_CONCAT(w.Mobile) AS Mobiles, max(date_of_sale) as most_recent_sale FROM Customers c JOIN Working w ON c.ClickPosID = w.ClickPosID GROUP BY w.ClickPosID) AS subq JOIN sales AS sales_joined ON (subq.date_of_sale = sales_joined.date_of_sale);[/code] In that "..." you really should be listing the columns you want. Using "*" is a habit I gave up long ago, because it makes things more confusing in complex queries. Particularly when you self-join like this, as you need to specify which copy of the sales table columns you want. Also be warned that mysql does not guarantee which entry you will get when you don't specify an aggregate like max or min. It may not always be the first one. That's just luck, because the data is stored in that order on disk.
  20. Try naming your variables txtservice[] in the html, and then reading as an array in php. You can also do this by reading the raw post data, but that's a hassle.
  21. Hi Michael, Mysql has a nice kludgy aggregate operator for situations such as this, which may simplify your job. SELECT CustID, count(*) as TotalPurchases, GROUP_CONCAT(ProductID) AS Products FROM Customers JOIN Sales ON ... GROUP BY CustID After that you can parse the concatenated products and off you go. Alternately you can select the whole lot as rows and group them in php, but that is a pain (though quite possible, and I've taken this approach many times, when aggregates aren't powerful enough for what I need)
  22. What do you see if you var_dump($row) at the top of your loop?
  23. You need this line $postdate = $year."-".$month."-".$day; That line is in your add script, but missing from your update script. It must come after you set $year, $month and $day, and before you use $postdate in your $sql.
  24. No it's NOT in the right format. Your query showed up as this: update navs set NetAssets='4',Nav='4', Date='' where id = '40'update navs set NetAssets='4',Nav='4', Date='' where id = '40' This means that your $postdate variable is empty. Empty is not the correct format. You need to determine why it is empty. It looks like you use day, month and year as your form variables. That means you need to take the variables $_REQUEST['day'], $_REQUEST['month'] and $_REQUEST['year'] and construct your date from them.
×
×
  • 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.