rdub Posted October 13, 2008 Share Posted October 13, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/ Share on other sites More sharing options...
F1Fan Posted October 13, 2008 Share Posted October 13, 2008 Use the number_format() PHP function. Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664172 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2008 Share Posted October 13, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664178 Share on other sites More sharing options...
rdub Posted October 13, 2008 Author Share Posted October 13, 2008 Thank you. I checked out the link. Not sure how I would include it in this code. Do you have a thought? "<br />"."<span class=style1d>"."<strong>"."$".$fetched['price']."</strong>"."</span>". Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664194 Share on other sites More sharing options...
wildteen88 Posted October 13, 2008 Share Posted October 13, 2008 Wrap format_number around your $fetched['price'] variable. Also why on earth are you doing "<tag>"."<another tag">".$var."</another tag">"."</tag>" It is better to do "<tag><another tag>$var</another tag></tag>" Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664204 Share on other sites More sharing options...
PFMaBiSmAd Posted October 13, 2008 Share Posted October 13, 2008 LoL, comma, not coma (must get a spell checker that knows what I want, not what I type.) Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664231 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Share Posted October 13, 2008 <?php echo number_format(245100);?> Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-664272 Share on other sites More sharing options...
rdub Posted October 14, 2008 Author Share Posted October 14, 2008 I'm way too new to this, sorry. Tried this but without results. <number_format ($fetched('price'), 2, '.', '')>"."<strong>"."$".$fetched['price'] Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665149 Share on other sites More sharing options...
kenrbnsn Posted October 14, 2008 Share Posted October 14, 2008 Please post that line in context with the rest of your code. It's really hard to tell what's wrong without the rest of your code, since there are quotes all over the place. Ken Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665164 Share on other sites More sharing options...
rdub Posted October 14, 2008 Author Share Posted October 14, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665175 Share on other sites More sharing options...
discomatt Posted October 14, 2008 Share Posted October 14, 2008 Pure MySQL solution http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_format SELECT FORMAT(`field`,0) FROM `table` Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665180 Share on other sites More sharing options...
wildteen88 Posted October 14, 2008 Share Posted October 14, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665197 Share on other sites More sharing options...
rdub Posted October 14, 2008 Author Share Posted October 14, 2008 Great. Almost there. Now shows decimal (don't need) but not the comma separating thousands. By the way, doesn't work at all without the quotes. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665217 Share on other sites More sharing options...
rdub Posted October 14, 2008 Author Share Posted October 14, 2008 Got it. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/128242-displaying-punctuation/#findComment-665226 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.