Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. It SHOULD be null before the global $db line. After global $db, it should be an object. The line "global $db;" is where $db is brought from global scope (ie outside all the functions) into local scope (ie inside the function). Is it still null after that line?
  2. Ok this is the key finding - $db was an object after it got instantiated, but later it's not an object anymore, it's null. I don't think protected has anything to do with it, because protected class members may be accessed from within the class itself. And, if that were the issue, you would get an error instead of $db being set to null. If you want to eliminate this as a cause, just declare them both public instead. Another probably minor issue - $lastResult is not the same as $lastresult. What I would do is start displaying the contents of $db in more locations, so you can pinpoint exactly where it changes from an object to null. You might want to tag each location as well, eg: print "<pre> Before checking SESSION[ulevel]: " ; var_dump($db) ; print "</pre>"; The "pre" tags will make the output more readable. Eventually you will narrow it down to a single line. Before that line, $db is an object. After that line, $db is null. And that's the line you need to fix.
  3. Searching in google for "fuzzy c means php" gave me this: http://www.jimstoik13.comoj.com/?p=80 I have no idea if that's what you are looking for, since I don't know what fuzzy c means are. But at least it's in php
  4. PHP is saying $db is not an object - what is it then? I would use var_dump() to show what is in $db before it is assigned, after it is assigned (after line 5 of list.php), and just before it is used in contents(). Once you've confirmed that it is correct after it is created but incorrect when used in contents(), start checking its value in between the points where you have already checked it, to find where it changes.
  5. Do you have multiple "meta_key" for each user, each with a "meta_value"? And do you need to check one meta_key for a particular condition and another meta_key for another condition?
  6. There's many good technical reasons why it may not work. What you are measuring is the time for an echo, a call to ob_flush() and a call to flush(). These calls may get blocked due to insufficient space in an output buffer, or they may get to run instantly because there's available space. Or they may make a system call which results in your process getting put to sleep, and then other processes may run in the meantime, before you finish measuring. Both explanations are consistent with seeing reduced times after adding a sleep() between each measurement. You might need to work at a lower level, such as a raw socket, to get more accurate timing. Then PHP's buffering won't be involved.
  7. Do you want to count the number of entries with county = 1 or county = 2 and get a total for each user id?
  8. Well that is rather unusual. I can think of some theories, such as sleeping affecting the scheduler or affecting how much data is buffered and waiting to be sent when you output the next chunk. But at the end of the day, iare you getting the intended behaviour? Is the data rate limited? If so, it doesn't matter that you're getting unexpected measurements.
  9. Ok, in the form you have this: <input name="id" input type="hidden" value="<?php $dbid ?>" /> That creates a hidden input in your form with name "id" and value from $dbid. When the form is submitted using post, that same value can be used in your script as $_POST['id']. So if you use that id when you update the database, you should find that you only update the answer for that one question. The other thing you need to do is specify which radio button is selected when printing out the radio buttons, using "checked". An example is here: http://www.echoecho.com/htmlforms10.htm In your php you'll need to check if that question is currently answered true or false, and only put "checked" on the corresponding input tag.
  10. Another option would be to do a curl request from php, posting the data to the backup server. Then you avoid a new process, but you still make a new tcp connection each time. If you have a huge amount of traffic you might consider keeping a single tcp connection open constantly, or sending the data over udp (over a reliable local network). It all depends on how much you need to scale really. Each successive optimization is more complex.
  11. $POST['id'] should have the id of the question which was answered.
  12. That looks like serialized data to me. In which case you can do this: $meta_value = unserialize($line['meta_value']); if ($meta_value['county'] == '4') { ... }
  13. The "AND" you're thinking of is "OR" in sql. The thing to remember is that SQL checks the condition on each result, not on the entire set of results. So if you say "SELECT * FROM pets WHERE type = 'dog' AND type = 'cat'", it will look at the first pet and ask "Is this a dog AND is it a cat too?". Then it'll look at the second pet, checking if it's a dog-cat. And it'll never find a dog-cat, because they don't exist. But if you ask for pets which are dogs OR cats, it'll look at the first pet and ask "Is this a dog OR is this a cat?". And it'll find all pets which are either dogs OR cats. So the problem is most likely that there are no results where folder = 'politics', or that your code that follows is not displaying them.
  14. Yep that's a bad way to do it. A better way is to check the password and store a variable in $_SESSION, such as $_SESSION['admin_login'] = true. An even better way is to compare against a salted md5 hash as Muddy is suggesting, and THEN set $_SESSION['admin_login'] = true. Storing the password in a cookie leaves too many opportunities for the password to be observed by someone else. Make sure you empty the session on logout and set $_SESSION['admin_login'] false when appropriate (such as when another user logs in).
  15. Or str_replace(), if you are replacing fixed strings with other fixed strings. You would most likely read in all the replacement values and use str_replace() on each one if using that approach. preg_replace() has more advanced features, such as being able to call a function for each replacement, with the 'e' modifier. That would allow you to include a different file depending on which tag was found, for example.
  16. Yes your one query should be fine. You can make an "if" using $line['meta_value'] inside the loop. If you want the results in a particular order you can use an "ORDER BY" clause in your SQL query.
  17. Your code looks correct to me. What exactly is the problem you have with the second sample code? How are the measurements affected? Sample output would be good, including output of every value that goes into calculating the overall average.
  18. You can't set the value of a variable to a dynamic value, which includes $_SERVER, in the class's variable declarations. Instead you can set it in the constructor.
  19. A common structure for a tree with unlimited levels in SQL is to have an id column, and "parent" columns in each row. To find the children of a row X, you select "where parent = X", which will be fast with the parent column indexed. To find the parent of a row you just fetch the parent column directly from that row.
  20. You could try using this: http://au.php.net/manual/en/function.mb-convert-encoding.php Or, mysql probably has some built-in functions to convert encoding. I am guessing you need to convert from latin1 (aka iso-8859-1) to utf8.
  21. mod_gzip allows you to compress the output of your php script, to save bandwidth. The browser will uncompress it again and the result (in theory) will be a faster website.
  22. if ($stats->id == 201) echo $stats->name."\n"; Does that do what you want?
  23. It sounds like proximity is the key. If points from different polygons are close to each other, they probably should be merged. But you still need to determine which points lie on the edge. I have an idea for how to do that but no time to formalize it now. The idea is to define the center, then find points which lie furthest away for each polygon (where furthest away is defined as not being behind any line formed by any other 2 points of the same polygon). Then link those far points according to whichever far points on another polygon are closest.
  24. I'm not sure clipping algorithms can apply here.. and the standard convex hull algorithms don't work either. Do you have a precise definition of what you are trying to find? The question I keep asking is, for example with the top left and the top polygons, how do you know you should link the two corners of those polygons and not any other? Is it because the corners are close to each other? How about this: 1. Find the outermost points, where outermost is yet to have a formal definition (defining this doesn't seem obvious to me) 2. If an edge already links two outermost points, include that edge in the final polygon 3. If two edge sets linking outermost points are not linked together, link them together using the closest points available (only considering points that mark the start and end of a set of edges).
×
×
  • 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.