Reputation: 3697
I have a query which I am outputting the number of results using mysql_num_rows. This works fine but I am wanting to output the result as separate numbers. So the result could be 1505 but I would like to use each single digit as its own number so I can apply css styling to it similar to the tutorial here http://blogupstairs.com/css-flip-counter-experiment/
I dont care for the flip part of the tutorial, only the styling. I can do the styling but I just need to know if its possible to split the result into separate digits and still be able to still apply number formatting so I would have 1,505.
Need any more information?
Upvotes: 0
Views: 148
Reputation: 115
$number = mysql_num_rows;
$chars = preg_split('//', $number, -1, PREG_SPLIT_NO_EMPTY);
foreach($chars as $char){
echo("<span class='nr'>$char</span>");
}
then just css span.nr
Upvotes: 0
Reputation: 212452
$number = 1505;
$digits = str_split(number_format($number,0));
var_dump($digits)
You now have an array of digits and can manipulate each one individually however you wish...
foreach($digits as $digit) {
echo '<div class="mySpecialClass">' . $digit . '</div>'
}
note that you will also have , (as you requested) as one element in your array if the number was 1000 or higher
Upvotes: 1