Jump to content

[SOLVED] Decimal Align?


twilitegxa

Recommended Posts

Is there a way to code this to where the number line up at the decimals? I was reading about the number_format function, but I can't get it to work right. Can anyone help? Here is the code I wish to use it on:

 

<?php
$get_sub_attributes = "select * from scout_sub_attributes where identity = '$identity'";
$get_sub_attributes_res = mysql_query($get_sub_attributes, $conn) or die(mysql_error());

while ($sub_attributes_info = mysql_fetch_array($get_sub_attributes_res)) {
$sub_attributes_id = $sub_attributes_info['id'];
$sub_attributes_identity = $sub_attributes_info['identity'];
$sub_attributes_attribute_id = $sub_attributes_info['sub_attribute_id'];
$sub_attributes_level_id = $sub_attributes_info['level_id'];
$sub_attributes_notes = $sub_attributes_info['notes'];

$get_sub_attribute_names = "select * from sub_attributes where id = '$sub_attributes_attribute_id'";
$get_sub_attribute_names_res = mysql_query($get_sub_attribute_names, $conn) or die(mysql_error());

while ($sub_attribute_names_info = mysql_fetch_array($get_sub_attribute_names_res)) {
$sub_attribute_names_id = $sub_attribute_names_info['id'];
$sub_attribute_names_attribute = $sub_attribute_names_info['sub_attribute'];
$sub_attribute_names_points = $sub_attribute_names_info['points'];
$sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id);

$display_block .= "
<tr>
<td class=indent>$sub_attribute_names_attribute</td>";

if ($sub_attributes_level_id == null) {
$display_block .= "$sub_attributes_level_id";
} else {
$display_block .= "
<td class=align_levels>$sub_attributes_level_id</td>
<td class=align_levels>$sub_attributes_points</td>
</tr>";
}
?>

 

The variables I want decimal aligned are $sub_attributes_level_id and $sub_attributes_points. How can I do this?

Link to comment
https://forums.phpfreaks.com/topic/171480-solved-decimal-align/
Share on other sites

I see what you did, but I can get it to work for this calculation:

 

$sub_attributes_points = ($sub_attribute_names_points * $sub_attributes_level_id);

 

I tried this:

 

$sub_attributes_points = number_format ($sub_attributes_points , 0 , "." , ",");

 

But nothing happened. What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/171480-solved-decimal-align/#findComment-904281
Share on other sites

Well, i already have the text-align set to center on the table cell, so I can't figure out how to do both, so I guess I will close this topic as solved and give up on doing it. What I wanted to do was have the cell centered as well as have the numbers being displayed in it aligned to the decimal:

 

So instead of this -

 

4

5

10

 

I'd have:

 

  4

  5

10

 

It is sort of hard to line up, but I think you can see what I mean.

Link to comment
https://forums.phpfreaks.com/topic/171480-solved-decimal-align/#findComment-904563
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.