1. The trade part of Lethal Zone has fully been taken over by FoG (Fortress of Gamers) and this site can no longer be used to make appeals. If you feel that your tag is unjust, please file an appeal over at https://f-o-g.eu.trade instead.

php programmer?

Discussion in 'Lethal Chat' started by Snelvuur, Aug 19, 2010.

  1. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    So just a heads up..

    do we actually have some descent php programmers on this board? since i want to abuse that person now and then. Jojo davis has some knowledge, i have some of my own.

    But i dont know if we have more "good" guys in php. Would really help me out if we have one that could take a look at code and says "this can be much easier like this and that" :)

    building something for the community (admin wise)
     
  2. antou(fr)

    antou(fr) Registered

    Joined:
    Jul 26, 2010
    Messages:
    2,017
    Likes Received:
    2
    Well, I know php but i didn't code since some times. Maybe I can help, not sure tho...
     
  3. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well i would need a descent one, that aint afraid of some function/routines/some unique key constraints in mysql etc etc..
     
  4. antou(fr)

    antou(fr) Registered

    Joined:
    Jul 26, 2010
    Messages:
    2,017
    Likes Received:
    2
    Oh then, not sure i'd be the good one ^^ anyways i don't think i would have enough time to give to such a project... :( later maybe
     
  5. Fixxy

    Fixxy Registered

    Joined:
    Oct 8, 2009
    Messages:
    733
    Likes Received:
    5
    Heyo Snelvuur.
    I have experience in php programming, i have a bunch of projects on php %)
    So i can help you.
     
  6. Pablosky

    Pablosky Potato supreme

    Joined:
    Aug 18, 2009
    Messages:
    1,652
    Likes Received:
    0
    Well, I try to do as much as possible with PHP (seriously, I emulated cmd.exe with it, for the hell of it), so maybe I can be of some help as well.
     
  7. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well i did manage to do the parts i wanted, but if i need further help, i know where to get it :)
     
  8. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    Ok, i got a question.. this is my database output:

    mysql> select distinct version from mods;
    +-----------+
    | version |
    +-----------+
    | 1.3.2-dev |
    | 1.3.4 |
    | 1.3.5-dev |
    | 0.5.5 |
    | 3.2.9 |
    | 0.6 |
    | 1.0 |
    | 1.6.2 |
    | 1.6.3 |
    | 1.1 |
    | 1.1.0 |
    | 1.2 |
    | 1.2.1 |
    | 1.1.5 |
    | 0.2 |
    | 1.0.0.0 |
    | 1.2.100 |
    | 1.4.2 |
    | 1.4.5 |
    | 1.4.6 |
    | 1.1.3 |
    | 2.0.9 |
    | 1.0.6 |
    | 2.0 |
    | 2.6.0.5 |
    | 1.5.5 |
    | 1.0.1 |
    | 1.0.2 |
    +-----------+
    28 rows in set (0.01 sec)

    I can remove the "-dev" stuff that aint a issue.

    But how would i know which version is the newest one since it uses mostly x.x.x format?
     
  9. Q-Ball

    Q-Ball Registered

    Joined:
    Oct 7, 2009
    Messages:
    1,441
    Likes Received:
    0
    Why don't you just transform all version numbers in X.X.X.X format and then change -dev to .2 or something like that?
     
  10. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well i understand a lot of the "why dont you just bla bla" but thats the point, how do i bla bla?

    examples of code somewhere?
     
  11. Anonymous

    Anonymous Guest

    You could use
    Code:
    ORDER BY version DESC
    , so you've got them sorted from newest to oldest. But there is one thing. The 1.0.0.0 will be "newer" than 1.0
     
  12. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    yeah, so thats not a good sollution :) we need a better one.

    als that mysql_last_id thingy, that gets the latest id from a auto increment does not always work. If you empty the tables, and create a new one it will still count further and not take the last id.
     
  13. antou(fr)

    antou(fr) Registered

    Joined:
    Jul 26, 2010
    Messages:
    2,017
    Likes Received:
    2
    Well, if you're sure you'll always have the x.x.x.x format, you can try to remove the dots using regular expressions (i don't really master regexp so don't ask me how ^^) to get to a more conventional format (xxxxx, or 10210 instead of 1.0.2.1.0 for example).
    For each version, count how many characters there are (there is a php function for that, strcount or something like that ^^), keep the highest and add zeros behind the versions that have less characters (ex: if you have 1.2 and 1.0.0.1, you need to get 1200 and 1001).

    Then just use a "while" loop with which one you keep the highest of your entries.

    No ?
     
  14. Pablosky

    Pablosky Potato supreme

    Joined:
    Aug 18, 2009
    Messages:
    1,652
    Likes Received:
    0
    Gave it a couple seconds thought. Here you go, good sir.
    <?php

    $versions = array( '1.10.2', '1.5.50', '1.7', '1.10.3', '1.9.9', '1.7.0', '1.5.6' );

    foreach( $versions as &$version ) {

    $numbers = explode( '.', $version );
    foreach( $numbers as &$number )
    $number = strlen( $number ) . $number;
    $version = implode( '.', $numbers );

    }

    rsort( $versions );

    foreach( $versions as &$version ) {

    $numbers = explode( '.', $version );
    foreach( $numbers as &$number )
    $number = substr( $number, 1 );
    $version = implode( '.', $numbers );

    }

    echo '<pre>';
    print_r( $versions );
    echo '</pre>';

    ?>
    It currently outputs
    Array
    (
    [0] => 1.10.3
    [1] => 1.10.2
    [2] => 1.9.9
    [3] => 1.7.0
    [4] => 1.7
    [5] => 1.5.50
    [6] => 1.5.6
    )
    It uses one loop to add a digit representing the length of each number before the number and a second to remove it again after the sorting has been done. This way a 10 excels a 5 because of the latter having a shorter length. This may cause problems with numbers like 01, but that's easy to fix. Thought you rather wanted a quicker working code than a completely-superduper-foolproof code.
     
  15. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well so far so good.. now all i need is a query to go with it from mysql :)
     
  16. antou(fr)

    antou(fr) Registered

    Joined:
    Jul 26, 2010
    Messages:
    2,017
    Likes Received:
    2
    Why ? What are you trying to do once your entries are ordered ?
     
  17. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well i want to be able to show the version numbers of several machines and then indicate which one is the latest. If it matches the latest then show it green, otherwise show it red.
     
  18. Pablosky

    Pablosky Potato supreme

    Joined:
    Aug 18, 2009
    Messages:
    1,652
    Likes Received:
    0
    I don't really understand, do you want a single query to run through MySQL and receive the contents ordered by version (so the whole code in pure MySQL)?
    Or do you want my example modified to also supply the query it needs?

    To put it this way: is it fine with you if you if you get a sorted array with only the versions back after running the code?
     
  19. Snelvuur

    Snelvuur King of Sand

    Joined:
    Sep 27, 2008
    Messages:
    4,036
    Likes Received:
    76
    well since we had a chat, it seems to be clear :)
     
  20. Alias

    Alias Registered

    Joined:
    Jun 6, 2009
    Messages:
    2,959
    Likes Received:
    0
    Im doing php nexy year in uni, looks like it will be pretty easy ;)