David:

For number formatting, in your below example, use:
<?php
foreach( $data as $r ) {
        print number_format( $r['Numerals'] );
}
?>
http://us2.php.net/manual/en/function.number-format.php

For date formatting, try grabbing the date from MySQL in the format you want to use:
SELECT DATE_FORMAT( date_field, '%M %D, %Y' ) AS `Dates` FROM ...
and then just print $r['Dates'] would work.
http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html


Otherwise, you could use PHP's date formatting functions as well (assuming you are getting the date in YYYY-MM-DD format:
<?php
foreach( $data as $r {
list( $year, $month, $day ) = explode( "-", $r['Dates'] );
$formatted_date = date( "F jS, Y", mktime( 21, 39, 0, $month, $day, $year ) );
print date( "F jS, Y", $timestamp );
}
?>
http://us2.php.net/manual/en/ref.datetime.php


As for the imported numbers showing up as they are, perhaps you are importing them into SMALLINT field, which has an upper signed limit of 32767. Try changing your field type to INT or MEDIUMINT, depending on the range of numbers imported, and whether or not there are any negatives.
http://dev.mysql.com/doc/mysql/en/Numeric_type_overview.html


Wes

On Jun 26, 2004, at 8:47 PM, David Blomstrom wrote:

I asked some questions about displaying numerals and
dates recently and got some good feedback. Now I'm
ready to do it - but I'm doing something wrong.

Consider the table below, where the field "Numerals"
displays regular numerals (e.g. 2500) and "Dates"
displays dates.

Exactly how would I rewrite this so that commas are
inserted in numerals (2,500 vs 2500), and dates (e.g.
2004-12-28) are displayed like "December 28th, 2004,"
or "Dec. 28, 2004"?

<table class="sortable" id="tab2000">
<tr><th class="tabstate" colspan="8">Campaign
2000</th></tr>
<tr>

<td><?php foreach ($data as $r) { print
$r['Numerals']; } ?></td>

<td><?php foreach ($data as $r) {
print(date_format($r['Dates'])); } ?></td>

</tr>
</table>

Also, there's something really weird going on with my
numerals. I saved a Microsoft spreadsheet as a CSV
file, which I then imported into MySQL.

But many of the numerals were transformed to 32767 in
my database. Here's a sample line from the CSV file,
which illustrates that just one numeral is surrounded
by quotes:

921781,"472940",422768,13421,7358,5294

In this particular example, the last two numerals
display correctly in the database, but the other four
don't - including the numeral surrounded by quotes.

Any idea what's going on here? Thanks.


__________________________________ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]





--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to