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)
well i would need a descent one, that aint afraid of some function/routines/some unique key constraints in mysql etc etc..
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
Heyo Snelvuur. I have experience in php programming, i have a bunch of projects on php %) So i can help you.
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.
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?
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?
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?
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
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.
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 ?
Gave it a couple seconds thought. Here you go, good sir. Spoiler <?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 Spoiler 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.
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.
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?