twilitegxa Posted September 18, 2008 Share Posted September 18, 2008 Is there a way to align an entire column in a table to a decimal point? I have values in my table as: 1 16 2 10 2 etc... But I do not want them centered or right or left aligned. I prefer they are aligned to the decimal kind fo like this (they just don't like up right on here, but hopefully you get the idea): 1 16 2 10 2 Is there a way to do this? My data is being pulled from a database and displayed using PHP, if that makes a difference. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 So you want everything to be aligned with the decimal place as the centerpiece? Like: 1.10 and 11.0 or close to that? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 Yes, except I don't actually have decimals in my numbers. But I thought it would assume the decimal is at the end, like in math classes lol i.e. 10 = 10.0 Will is work if i have no actual decimals and is there a way to do it? Quote Link to comment Share on other sites More sharing options...
dropfaith Posted September 18, 2008 Share Posted September 18, 2008 http://www.w3schools.com/tags/att_col_align.asp is all i can think of but has horrible support firefox and safari will ignore this Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 18, 2008 Share Posted September 18, 2008 Take a look at string padding in the manual - http://ca.php.net/manual/en/function.str-pad.php Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 I don't understand the string padding thing. Can you help explain it better to me and how I can use it? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 You could also use tables and cheat a little. Split the number up by the decimal and do this: <table> <tr> <td align="right">1</td><td align="center">.</td><td>10</td> </tr> <tr> <td align="right">10</td><td align="center">.</td><td>0</td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 18, 2008 Share Posted September 18, 2008 I don't understand the string padding thing. Can you help explain it better to me and how I can use it? I couldn't explain it better than the manual and the user notes/examples on the same page. Specifically, what's the problem you're having with the function? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 I don't know how to use the function. :-\ Also F1Fan, I don't think I can use tables to separate the decimals because I am using table to display the data already but from a database. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 That's OK, you can put a table within a table. Like this: <table><tr><td> <table> <tr> <td align="right">1</td><td align="center">.</td><td>10</td> </tr> <tr> <td align="right">10</td><td align="center">.</td><td>0</td> </tr> </table> </td></tr></table> Please excuse the horrible layout. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 But...I am pulling the numbers from my database. Can I still do that? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Sure you can. Post all of that section of code, the loop at least. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 This is the code I have: echo "<table border='0' width='40%' id='stats'>"; echo "<tr><td colspan='3' id='th'>Character Attributes And Sub-Attributes</td></tr>"; echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td>Level</td><td>Points</td></tr>"; echo "<tr><td><td></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['attribute_id']; echo " "; echo $row['desc']; echo "</td><td>"; echo $row['level']; echo "</td><td>"; echo $row['points']; echo "</td></tr>"; } echo "</table>"; for that part of my page. I tried changing it to this: echo "<table border='0' width='40%' id='stats'>"; echo "<tr><td colspan='3' id='th'>Character Attributes And Sub-Attributes</td></tr>"; echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td>Level</td><td>Points</td></tr>"; echo "<tr><td><td></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['attribute_id']; echo " "; echo $row['desc']; echo "</td><td><table><tr><td class='right'>"; echo $row['level']; echo "</td></table></td><td>"; echo $row['points']; echo "</td></tr>"; } echo "</table>"; because I have a class named 'right' in my CSS that is set to text-align: right, but it didn't work. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Which one is the one you want split up? If there's other data going into the table, you may have to include it in the existing table. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 The part of the table that includes the 'level' and 'points' from the database. Those two fields are numbers and I want them to be like decimal aligned instead of just right aligned because the cell above those cells is centered and I want the level and points data to be sort of centered within the table, but also decimal aligned within that cell. Does that make sense? Here is a link to the example so you can see it in real time. It might help. http://www.webdesignsbyliz.com/sailormoonrpg/test.php Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 OK, I think I completely understand now. I thought I did before, but looking at your page made me realize exactly what you want. This will end up a little weird, but here goes: <?php echo "<table border='0' width='40%' id='stats'>"; echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>"; echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>"; echo "<tr><td><td></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['attribute_id']; echo " "; echo $row['desc']; echo "</td><td width='2%'></td><td width='1%' align='right'>"; echo $row['level']; echo "</td><td width='2%'></td><td width='1%' align='right'>"; echo $row['points']; echo "</td><td width='2%'></td></tr>"; } echo "</table>"; ?> That's an experimental try. Let me know how it goes. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 Nope, LOL That messed it up. Refresh thepage to see what I mean. I think we forgot to make a table within the table? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 LOL, I see! No, after I saw your code, I decided the table within a table wouldn't do what we want. Try this one (it will at least make the code easier to look at when you view the source): <?php echo "<table border='0' width='40%' id='stats'>"; echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>"; echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>"; echo "<tr><td></td></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['attribute_id']; echo " "; echo $row['desc']; echo "</td><td width='2%'> </td><td width='1%' align='right'>"; echo $row['level']; echo "</td><td width='2%'> </td><td width='2%'> </td><td width='1%' align='right'>"; echo $row['points']; echo "</td><td width='2%'> </td></tr>"; } echo "</table>"; ?> I missed some stuff. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Arg, I missed one thing: <?php echo "<table border='0' width='40%' id='stats'>\n"; echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>\n"; echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>\n"; echo "<tr><td></td></tr>\n"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { echo "<tr><td>\n"; echo $row['attribute_id']; echo " "; echo $row['desc']; echo "</td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['level']; echo "</td><td width='2%'> </td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['points']; echo "</td><td width='2%'> </td></tr>\n"; } echo "</table>"; ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 I don't think it helped. LOL This is so hard to figure out for me! Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 I mean the alignment looks right, but my other row is messed up. Let me double check my code again. Maybe i forgot to paste something. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 Okay, that did work! Yay! Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 WOO HOO! Is that what you wanted? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 Yes! Thank you so much! Do you know anything about, I guess it would be if else statements? See the part in the table where it says all the Items Of Power? What I actually want it to do is display the term Item Of Power once, and then the actual items of power underneath. Kind of like: Item Of Power - Upgraded Sailor Suit 1 2 - Moon Tiara 1 2 ect. Do you know how I can do this? I have the items of power listed in the desc field of my table in my database. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Yes, but I'm signing off for tonight. I'll help you with it tomorrow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.