Jump to content

[SOLVED] Print results, table alignment


Petrushka

Recommended Posts

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? 

Link to comment
https://forums.phpfreaks.com/topic/57954-solved-print-results-table-alignment/
Share on other sites

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>";  
?>

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.