Jump to content

vinny42

Members
  • Posts

    411
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by vinny42

  1.  


    But how do I find all descendants of section 144 without querying every single section and working my way up the hierarchy?

     

    What barand is saying is that you only want to know which nodes in the supplied array are descendants of 144. So if you make an array that contains *all* descendants of 144, you can just compare the two arrays.

     

    Whether this is an option depends on the size of your tree relative to the number of nodes you are looking for.

  2. "Warning: Illegal string offset 'content' in C:\www\mvc\libs\Words.php on line 14"

     

     

    As requinix suggests and as the error message is trying to tell you: whatever you are trying to get element 'content' from at line 14 is a string, not an array. Strings cannot have an offset of anything other than a number.

  3.  


    looking at it i'll try this:

     

    You souldn't try things out, you should read about what you are doing and fix your mistake.

     

    You cannot LEFT JOIN during an insert because you are creating a new record so there is no record to join yet.

     

    Perhaps you should start by saying what you want to achieve, there mist be a reason why you wanted to use the JOIN?

  4.  


    When you're going so deeply in the hierarchically tree structure, your code will get much harder to read from you or somebody else after at time.

     

    That's a matter of documentation. If you don't know PHP then a PHp solution is not going to be any easier to read.

     

    More to the point; is this soemthing the database should do and can do?

    For MySQL the answer is no, MySQL cannot do recursion by itself, so you'll have to do the recursion in PHP. That does *not* mean that you load all records in PHP, because PHP isn't opartcularly brilliant at processing lots of data either.

    For PostgeSQL the answer is yes, PostgreSQL can do a recursive selfjoin, which does exactly what is required here.

  5. Nested set is brilliant for finding parents and entire trees, but it is pure hell to maintain as the tree gets bigger.

     

    A simple compromise is to add a new column that holds the entire path to each record, reducing the problem to a LIKE query, which may or may not be faster than recursing through the parents. (MySQL cannot index for LIKE, other databases can use TRIGRAM indexes which are designed for this purpose)

  6. When you submit the form the remote server will send you something that it can use to identify you by. It you don't catch that data and send it along in your next request then the server will assume that you are not logged in.

     

    So you'll have to investigae how the login process works.

     

    You should probably also think about what you want to do; if the remove server want's you to be able to automate the posting , wouldn't it have an API?

  7. The biggest threat is SQL-injection. The script takes data from the POST vars and puts it directly into the query, which means that a hacker can literally put anythng he wants into the query. That incluses subqueries that do nasty things like create new admin accounts, drop the entire database, etc.

     

    Like Ch0cu3r says: this script is old (http_post_bars has been removed from PHP for years) and needs to be re-written with security in mind.

  8.  


    Maybe a better way, but you could have a large increment in the order numbers, like 100, 200, 300, etc...

     

    You could do that; make large gaps and put new numbers right in between. inserting between 100 and 200 yould be 150, between 100 and 150 at 125 etc. But in the end that's just postponing the envitable, you will have to renumber some time.

  9.  


     but say there are 30 items and I need to add a new item in position 2 everything below it needs to be renumbered.

     

    True, but that is one query:

     

    UPDATE table SET order_column = order_column+1 WHERE order_column >= X;

    where X is the order_column value of the first record that needs to be moved. 

    And you could even stick that in a trigger and not have to worry about it ever again. :-)

     

    You should perhaps use a separate table for this data, the sortorder itself is not part of the daa being sorted and if you ever decide to sort the same items differently in two dropdowns (of wherever) you don't want to have to add a new column every time.

  10.  


    This kind of headache illustrates exactly why it's better to store files in the file system than the database. 

     

    +42. If you're not doing anything with processing or distribution then files go in the filesystem.

     

    That said, you might be able to put the binary data of the image in the tag itself, which would reduce the number of hits your server takes (but if you want to reduce hits you have a busy server and a busy server shouldn't have a huge datafile for the database unles it's a big server...)

  11.  


    for now i need advise if im doing correct.!  

     

    What's the point? You are just going to ignore what's being said and do your own thing, just like you are doing now. I've already told you that you cannot simply merge data, but you do it anyway.

  12. I've modified the user example from the manual a little. It calls a URL containing a script that just has "sleep(1)" in it. If you run the code it will return in just over one second, while it has called the URL three times, so in blokcing mod it would have taken over three seconds.

     

     function multiHTTP($urlArr){    $sockets = Array(); // socket array!    $urlInfo = Array(); // info arr    $retDone = Array();    $retData = Array();    $errno   = Array();    $errstr  = Array();    for ($x = 0; $x < count($urlArr); $x++) {        $urlInfo[$x]          = parse_url($urlArr[$x]);        $urlInfo[$x]['port']  = (isset($urlInfo[$x]['port']) ? $urlInfo[$x]['port'] : 80);        $urlInfo[$x]['path']  = ($urlInfo[$x]['path']) ? $urlInfo[$x]['path'] : "/";        $urlInfo[$x]['query'] = (isset($urlInfo[$x]['query']) ? $urlInfo[$x]['query'] : '');        var_dump($urlInfo[$x]);        $s = fsockopen($urlInfo[$x]['host'], $urlInfo[$x]['port'],                       $errno[$x], $errstr[$x], 30);        if (false !== ($s)) {            $sockets[$x] = $s;            socket_set_blocking($sockets[$x], false);            $query          = ($urlInfo[$x]['query']) ? "?" . $urlInfo[$x]['query'] : "";            $strHTTPRequest = "GET " .                              $urlInfo[$x]['path'] . "$query HTTP/1.0\r\nhost: " . $urlInfo[$x]['host'] . "\r\n\r\n";            // echo $strHTTPRequest;            fputs($sockets[$x], $strHTTPRequest);            $retData[$x] = '';        }    }     // ok read the data from each one    $done = false;    while (!$done) {        for ($x = 0; $x < count($urlArr); $x++) {            if (false === $sockets[$x]) {                unset($sockets[$x]);                continue;            }            if (!feof($sockets[$x])) {                if ($retData[$x]) {                    $retData[$x] .= fgets($sockets[$x], 128);                }                else {                    $retData[$x] = fgets($sockets[$x], 128);                }            }            else {                $retDone[$x] = 1;            }        }        $done = (array_sum($retDone) == count($urlArr));    }    return $retData;} var_dump(multiHTTP(array("http://localhost/a.php?wait=1", "http://localhost/a.php?wait=2", "http://localhost/a.php?wait=3"))); exit;

×
×
  • 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.