Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Why are the containers relevant? Let's take an example: f'(x) where f(x) = sin(x^2)cos(x) = (sin(x^2)cos(x))' = sin'(x^2)cos(x) + sin(x^2)cos'(x) (product rule) = dsin(x^2)dx^2 * dx^2/dx * cos(x) - sin(x^2)sin(x) (chain rule on left, cos' = -sin on right) = 2xcos(x^2)cos(x) - sin(x^2)sin(x) (sin' = cos, x^2' = 2x) Nowhere do you need to consider the context of the derivative being found. You only ever need to consider what is inside, and use the appropriate rule to push the derivative further down into the expression.
  2. I'm asking for you to print the query itself, not the query results $sql is the variable name you use for your queries.
  3. I think there's some benefit to treating coefficients and powers specially. But functions I would treat as first class objects rather than modifiers. Things like e^x can get special treatment, as a first class function. Eg (ln(sin(x)))' Is this x modified by sin modified by ln? I think it's simpler to see it as ln of sin of x. Then the chain rule can be applied as an operation on the tree rather than an operation on modifiers of an object.
  4. Can you add "print $sql" before the mysql query in question, so we can see what query you are running?
  5. The problem there roopurt is that you differentiated the branches of the tree but not the "*" node. The product rule gives: (x*x)' = (x'x + xx') = (x + x) = 2x
  6. So what you want is to send an email as plain text, but have html entities interpreted? I don't think that's possible. Either you send it as html (in which case you must encode html entities), or you send it as text (in which case you must NOT encode html entities). If the mail reader interprets plain text as html, then that's a problem with the reader. There's not much you can do about that. Just to clarify, the security issue here is the possible display of html in the recipient's email client, right?
  7. $a['new_key'] = $a['old_key']; unset($a['old_key']); Because php uses copy on write, this will not make a second copy of the data.
  8. I think you need to escape all your input. For example: ... '".mysql_real_escape_string($_GET['sbcat'])."', ... For EVERY input string. Otherwise, people can send invalid input and hijack your database. And that's bad. You might want to print out your query too before executing it. That helps a lot for debugging.
  9. If you want such characters to show up in plain text, then you need to encode them in a plain text encoding, such as iso-8859-1. The way to do that is with html_entity_decode() Once you've got it in iso-8859-1 (aka latin1) I expect the mail reader should be able to read them properly..
  10. What error do you get when you try to run the query?
  11. Try this out (taken from here) $principal = 400000; $annual_interest = 0.07; $monthly_interest = $annual_interest / 12.0; $years = 30; $months = $years * 12; $monthly_payment = $principal * ( $monthly_interest / (1 - pow(1 + $monthly_interest, -$months))); print "Principal: $principal\n"; print "Annual interest: $annual_interest ($monthly_interest monthly)\n"; print "Years: $years ($months months)\n"; print "Monthly payment: $monthly_payment\n";
  12. You want to cover EVERY possibility? That's just not possible. Even the most powerful software has limitations. The first step is to decide what the scope of your program will be. For example, year 12 derivatives (in my country that's the final year of school), 1st year applied maths derivatives. What you need to cover then defines what your interface needs to be, and what your data structures need to cope with. roopurt's approach is definitely the most flexible. With that kind of structure, you just need to deal with simple rules at each node in the tree. The data structure in my earlier post is an example implementation of such a tree.
  13. Could that error be because the union eliminated table names? In which case you should just order by time instead of a.time Regarding the explain output, I'm a bit of a noob at reading mysql explains, so I'll leave that to the experts..
  14. btherl

    pgsql via PDO

    The examples I see here are different: <?php $stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?"); if ($stmt->execute(array($_GET['name']))) { while ($row = $stmt->fetch()) { print_r($row); } } ?> This is using a prepared transaction, but fetching the result data should be the same. $stmt->fetch() must be called to fetch each row individually.
  15. A general solver will be very complex.. I think you'll need to limit what you want to solve somehow. If you can limit it to expressions of the form c1x^n + c2x^(n-1) + ... then it's very simple. How to implement it depends very much on what classes of problems you need to solve. If you don't want to solve problems involving sin() then no need to implement sin(). Same for other functions like e^x, tan(), tanh(), etc etc. Maybe you can make an extensible data structure so you can add other functions later on. Something like $equation = array( 'type' => 'function', 'name' => 'sin', 'arguments' => array( array( 'type' => 'var', 'name' => 'x', ), ), ); And there you have it, sin(x). That structure can be extended to handle multiple arguments and can be nested as far as you want. Going for lunch now Will check for replies later.
  16. Can you give an example of the kind of problem you want to solve?
  17. Can you narrow the query down to a smaller query that still shows poor performance? For example, try the first select from the union, along with the order by condition, and see if that is still slow. At a glance, I suspect the problem is with your LIKE. LIKE can be a very slow operation, especially when it's not anchored at the start (that is, '%Apple%' is slow, but 'Apple%' can be much faster). The reason is that it requires examining every single row in the table. So try removing some of those LIKE conditions and see if things speed up. Once you've isolated what is causing the slowdown, it'll be much easier to suggest solutions.
  18. Hmm.. i've never requested data using the table name like that, but you can certainly do it by aliasing a column. For example, using your query in your latest post: SELECT r.userid AS ref_userid, ar.refid AS ar_refid, a.refid AS a_refid, a.firstname, a.lastname, a.becameaffiliate FROM affiliates a JOIN affiliatesreferals ar ON ( a.userid = ar.userid ) JOIN affiliates r ON ( ar.refid = r.userid ) WHERE r.refid = ".$_GET['id']." ORDER BY r.becameaffiliate In this case you can fetch ref_userid, refid, ar_refid, a_refid, firstname, lastname, becameaffiliate The columns which are unique can be fetched by name alone. But when they aren't unique, I usually use an alias. I'm not sure if there's other ways to do it.
  19. One approach is to specify what is allowed, rather than what is not allowed: $username = preg_replace('|[^[:alnum:]]|', '', $username); This will remove anything that is not "alnum", which includes a-z, A-Z and 0-9 only. Another option is to escape your usernames before output. In this case, any attempts to use html will result in the html displaying as source, and not being interpreted: print htmlspecialchars($username); From the manual for this function: "This function is useful in preventing user-supplied text from containing HTML markup, such as in a message board or guest book application."
  20. I'm sure he means register_globals. All the data you need is available in $_REQUEST and $_FILES. Try the following: print "<pre>"; var_dump($_REQUEST); var_dump($_FILES); Put that at the top of your script and see what's inside those variables.
  21. Note that you should not add quotes around 1 if rrn is an integer.
  22. $date_sql = "'" . mysql_real_escape_string($date) . "'"; $newcomments_sql = "'" . mysql_real_escape_string($newcomments) . "'"; $sql = "UPDATE `homepage` SET `date` = $date_sql, `comments` = $newcomments_sql WHERE `rrn` =1"; If you've already escaped your strings, you can skip that. But you need the single quotes around strings.
  23. Thanks, that clears up the database structure and your goals. Is the reason you are selecting storePK because you want to update the most recent row from the rows you summed with the newly calculated PTD? In which case you want the most recent storePK (which you can probably safely assume to be max(storePK)). In which case: SELECT SUM(sales) as sumSales, MAX(storePK) AS most_recent_storePK FROM Sales WHERE Sales.storeNum=259272 AND Sales.week<=4 AND Sales.period=1 AND Sales.year=2006 GROUP BY storeNum Then you can use most_recent_storePK to do the update. This is a bit dodgy because it may not always be true that the order of storePK matches the order of the entries. Really you ought to be selecting the correct storePK seperately. Another query won't hurt.
  24. When joining back to the same table, you need to give each copy an alias: SELECT ... FROM affiliates a JOIN affiliatesreferals ar ON (a.userid = ar.userid) JOIN affiliates r ON (ar.refid = r.userid) Now "r", which was joined to the refid, contains data for the referers. "a", which was joined to userid, contains the referees' data. For example, if r.username and a.username are in the same row, then r.username referred a.username
  25. It's difficult to help you without knowing your database structure. Presumably there are many storePK for each storeNum. What does storePK mean? What does storeNum mean? And how can you have a single storePK in your result when you are taking a sum that covers more than one storePK?
×
×
  • 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.