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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.