简体   繁体   中英

PHP mysql_num_rows split result

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?

$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

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM