Punten met PHP

Gestart doorKingunit15 reacties37 weergaven

16 berichten · pagina 1 van 2

Kingunit

Lid · Topicstarter

Berichten
10.409
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,

Stel ik laat info van mijn database zien, in mijn database staat er dus: 156702 , hoe kan ik ervoor zorgen dat de output 1 56 702 of 1.56.702 word?
0
Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
number_format(); ?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Bedoel je dit?

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
Functions by Daiman Meijers
website: daimanmeijers.nl
*/[/COLOR]
[COLOR= #007700]function[/COLOR] remnul[COLOR= #007700]([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$input[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$input[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
        [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]<=([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700])-[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700])) {[/COLOR]
            [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700].=[/COLOR] [COLOR= #0000BB]$input[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]];[/COLOR]
            [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++;
        }[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$output[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$input[/COLOR][COLOR= #007700];
    }
    
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] remnul[COLOR= #007700]([/COLOR][COLOR= #DD0000]0312312[/COLOR][COLOR= #007700]).[/COLOR][COLOR= #DD0000]"<br />"[/COLOR][COLOR= #007700];
function[/COLOR] arrayrek[COLOR= #007700]([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$nr[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
    [COLOR= #0000BB]$output[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]<=([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700])-[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700])) {[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]!=[/COLOR][COLOR= #0000BB]$nr[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]+=[/COLOR] [COLOR= #0000BB]$input[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$i[/COLOR][COLOR= #007700]];
        }[/COLOR]
        [COLOR= #0000BB]$i[/COLOR][COLOR= #007700]++;
    }[/COLOR]
    [COLOR= #0000BB]$output[/COLOR] [COLOR= #007700]= ([/COLOR][COLOR= #0000BB]$input[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$nr[/COLOR][COLOR= #007700]]-[/COLOR][COLOR= #0000BB]$output[/COLOR][COLOR= #007700]);[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$output[/COLOR][COLOR= #007700];
}[/COLOR]
[COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]12[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]25[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]13[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]28[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]19[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] arrayrek[COLOR= #007700]([/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]5[/COLOR][COLOR= #007700]);[/COLOR]
?>


Geschreven door Daiman, copyright bovenin laten staan!

toevoeging op 17 februari 2012, 07:38:35:
Ow, de eerste is dat hij decimale toevoegt, de 2e is dat hij alles in die array bij elkaar optelt tot een bepaald getal in de array geloof ik..

http://www.one2xs.com/threads/36242&p=1#531327

Is geloof ik niet wat je zoekt?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Zoals Dasaque zegt voldoet number_format(number, decimals, decimal_seperator, thousands_seperator) hiervoor.
0
Kingunit

Lid · Topicstarter

Berichten
10.409
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Zoals Dasaque zegt voldoet number_format(number, decimals, decimal_seperator, thousands_seperator) hiervoor.
Ik heb dat geprobeerd, maar ik krijg de punten niet op de juiste volgorde.
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoezo niet op de juiste volgorde?
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Hmm, waarom wil je eigenlijk 1.22.333 ? Wat voor nut heeft dat emo
0
Kingunit

Lid · Topicstarter

Berichten
10.409
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Eleky schreef:
Hoezo niet op de juiste volgorde?
Ik krijg gewoon de punten niet om het juiste plekje. Er komen standaard 6 getallen uit de database, en de punt(en) moeten altijd op het zelfde plekje komen.

toevoeging op 17 februari 2012, 19:46:05:
Rik schreef:
Hmm, waarom wil je eigenlijk 1.22.333 ? Wat voor nut heeft dat emo
Omdat het tijden zijn van een spel. Die worden opgeslagen in een database, dus is het: 1 minuut - 22 seconden - en 3 millie seconden.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] NumberToTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #FF8000]// $number moet MMssmmm zijn. (bijvoorbeeld: 0105200)[/COLOR]
    
    [COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] str_split[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]);[/COLOR]
    
    [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]3[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]4[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]5[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]6[/COLOR][COLOR= #007700]];
}[/COLOR]
?>


Of bedoel je iets anders?
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] NumberToTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #FF8000]// $number moet MMssmmm zijn. (bijvoorbeeld: 0105200)[/COLOR]
    
    [COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] str_split[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]);[/COLOR]
    
    [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]3[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]4[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]5[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]6[/COLOR][COLOR= #007700]];[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$result[/COLOR][COLOR= #007700];
}[/COLOR]
?>


@ Rogier: Je was de return vergeten wink
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Rogier schreef:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] NumberToTime[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #FF8000]// $number moet MMssmmm zijn. (bijvoorbeeld: 0105200)[/COLOR]
    
    [COLOR= #0000BB]$array[/COLOR] [COLOR= #007700]=[/COLOR] str_split[COLOR= #007700]([/COLOR][COLOR= #0000BB]$number[/COLOR][COLOR= #007700]);[/COLOR]
    
    [COLOR= #0000BB]$result[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]2[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]3[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]4[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]5[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #0000BB]$array[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]6[/COLOR][COLOR= #007700]];
}[/COLOR]
?>
Of bedoel je iets anders?

Dit werkt al niet met zijn voorbeeld omdat daar geen nullen voor de getallen staan.
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maar dat kan niet anders, want je kan nooit weten of Mssmmm of MMsmmm is.

Dus het is überhaubt de enige manier. (wat ik in de code aangeef)
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat je dan zou kunnen doen is controleren of het getal groter is dan 999999, zoja bestaat hij dan dus uit MMssmmm
Indien hij kleiner is bestaat het getal maar uit 6 getallen, en is het dus Mssmmm
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nee kan dan dus ook MMsmmm zijn of MMssmm
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat je dan zou kunnen doen is eerst alle 0en vervangen door os ofzo, en dan het goed weergeven en weer terug veranderen!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren