Jump to content

Displaying punctuation


rdub

Recommended Posts

I have a mysql field that contains numbers. When I display the info on my page it shows the numbers but not the comma such as in 245,100. Only shows 245100. no comma. I've tried different data types. Is this a database issue of php?

Link to comment
Share on other sites

This is human issue.

 

A coma in a number to separate fields in it to make it easier to read is a human convention, not a computer or a database convention.

 

You would need to format your number when you display it. Off of the top of my head, I don't know if mysql has a number_format function (you could look it up in the mysql manual), but php does - http://us2.php.net/number_format

Link to comment
Share on other sites

Here it is. Tried the working code without all of the quotes but received error.

The code below shows the results as before I added the change.

[code<?php
$display = 2;
$cols = 0;
echo "<table class=sample width=556 align=left";
while($fetched = mysql_fetch_array($result)){
   if($cols == 0){
       echo "<tr>\n";
   }
   
   
   // put what you would like to display within each cell here
   "<tr>\n";
   echo "<td width=378 valign=top>".$fetched['id']."<br />"."<span class=style1>"."<strong>".$fetched['Customer']."</strong>".
   ("<img src='" . $fetched['thumb'] . "' /> ") .
   "<br />"."<span class=style1e>".$fetched['hi_lite']."</span>".
   "<br />".$fetched['Phone'].
   "<span class=style1d>".$fetched['Description']."</span>".

   "<br />"."<span class=style1d>"."<number_format ($fetched('price'), 2, '.', '')>"."<strong>"."$".$fetched['price']."</strong>"."</span>".

   "<br /><a href='mailto:".$fetched['email'] . "'>". $fetched['email'] . "</a>";
   echo "<br /><a href='".$fetched['web'] . "' target='_blank'>". $fetched['web'] . "</a>";
   	"<br />".
   "</span>"."</td>\n";
?>

 

(edited by kenrbnsn to add


tags)

Link to comment
Share on other sites

Here it is. Tried the working code without all of the quotes but received error.

 

The code below shows the results as before I added the change.

 

<?

$display = 2;

$cols = 0;

echo "<table class=sample width=556 align=left";

while($fetched = mysql_fetch_array($result)){

   if($cols == 0){

       echo "<tr>\n";

   }

  

  

   // put what you would like to display within each cell here

   "<tr>\n";

   echo "<td width=378 valign=top>".$fetched['id']."<br />"."<span class=style1>"."<strong>".$fetched['Customer']."</strong>".

   ("<img src='" . $fetched['thumb'] . "' /> ") .

   "<br />"."<span class=style1e>".$fetched['hi_lite']."</span>".

   "<br />".$fetched['Phone'].

   "<span class=style1d>".$fetched['Description']."</span>".

 

   "<br />"."<span class=style1d>"."<number_format ($fetched('price'), 2, '.', '')>"."<strong>"."$".$fetched['price']."</strong>"."</span>".

 

   "<br /><a href='mailto:".$fetched['email'] . "'>". $fetched['email'] . "</a>";

   echo "<br /><a href='".$fetched['web'] . "' target='_blank'>". $fetched['web'] . "</a>";

   "<br />".

   "</span>"."</td>\n";

 

number_format is a function not a HTML tag! Cleaned your code up a bit

<?php
$display = 2;
$cols = 0;

echo "<table class=sample width=556 align=left";
while($fetched = mysql_fetch_array($result))
{
   if($cols == 0){
       echo "<tr>\n";
   }

   // put what you would like to display within each cell here
   "<tr>\n";
   echo "<td width=378 valign=top>".$fetched['id']."<br />".
        "<span class=style1><strong>".$fetched['Customer']. "</strong>(<img src='" . $fetched['thumb'] . "' /> )<br />".
        "<span class=style1e>".$fetched['hi_lite']."</span><br />".$fetched['Phone'].
        "<span class=style1d>".$fetched['Description']."</span><br />".
        "<span class=style1d><strong>$".number_format ($fetched('price'), 2, '.', '')."</strong></span><br />".
        "<a href='mailto:".$fetched['email'] . "'>". $fetched['email'] . "</a><br /><a href='".$fetched['web'] . "' target='_blank'>". $fetched['web'] . "</a>";
   	"<br /></span></td>\n";

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.