Petrushka Posted July 1, 2007 Share Posted July 1, 2007 I have managed to print my first set of results from my database. The last two columns, profit and balance are obviously numbers, and I'd like these two columsn only aligned to the right, so that the decimal points are in a uniform place. <?php // Connects to your Database mysql_connect("host", "database", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $data = mysql_query("SELECT * FROM tablename WHERE ref='2007-1' ORDER BY 'stable','date'") or die(mysql_error()); Print "<table cellpadding=2 width=100%>"; while($info = mysql_fetch_array( $data )) { Print "<tr>"; Print "<td>".$info['stable'] . "</td> "; Print "<td>".$info['date'] . "</td> "; Print "<td>".$info['time'] . "</td> "; Print "<td>".$info['track'] . " </td>"; Print "<td>".$info['horse'] . " </td>"; Print "<td>".$info['price'] . "</td> "; Print "<td>".$info['win'] . "</td> "; Print "<td align="right">".$info['profit'] . " </td>"; Print "<td>".$info['balance'] . " </td></tr>"; } Print "</table>"; ?> Thos returns the following error message: http://www.further-flight.co.uk/napsters/results.php How can I achieve this effect? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 1, 2007 Share Posted July 1, 2007 change Print "<td align="right">".$info['profit'] . " </td>"; to Print '<td align="right">'.$info['profit'].' </td>'; Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 1, 2007 Share Posted July 1, 2007 Yes you uses MadTechie's suggestion above also don't for get to align the balance to the right as well: Change Print "<td>".$info['balance'] . " </td></tr>"; to: Print '<td align="right">'.$info['balance'] . " </td></tr>"; Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 1, 2007 Share Posted July 1, 2007 I prefer the css route... .algnrght { text-align: right; } <?php print "<td class="algnrght">".$info['profit'] . " </td>"; print "<td class="algnrght">".$info['balance'] . " </td></tr>"; ?> You should also make sure that the decimal places are correctly displayed! - just in case its .00 <?php print "<td class="algnrght">". number_format($info['profit'],2,'.',',') . " </td>"; print "<td class="algnrght">". number_format($info['balance'],2,'.',',') . " </td></tr>"; ?> Quote Link to comment Share on other sites More sharing options...
Petrushka Posted July 1, 2007 Author Share Posted July 1, 2007 Excellent! Many thanks! 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.