View Full Version : Database Format Temperature Sign
jlsohio
02-05-2006, 06:20 PM
Can I format a number in mysql to display a degree sign?
Thanks.
jlsohio
vinyl-junkie
02-05-2006, 06:49 PM
Just use the ISO character set ° or numeric entity "& #176;" (run that all together, and without the quotes).
jlsohio
02-05-2006, 07:18 PM
Sorry, I'm not following your answer? I have to do this in PHP?
vinyl-junkie
02-05-2006, 09:31 PM
That's what the symbol is in HTML. Are you trying to format a query to capture the degree symbol or just display it in a page?
jlsohio
02-05-2006, 09:38 PM
I'm trying to format a PHP query to display it on the screen.
vinyl-junkie
02-05-2006, 09:53 PM
Um, forgive me for being so dense but are you trying to display the query itself, or do you have an element in your database with the degree symbol in it that you're trying to retrieve in a query?
jlsohio
02-05-2006, 11:38 PM
I have the temperature data stored in my database as an INT. I guess my question is more of a PHP question, but I want to display the results of my query using a degree sign.
I'm fairly new at PHP, but I have another question too. I'm getting this error:
Parse error: parse error, unexpected T_STRING
here's the php code I think is the issue:
// Request the text of all the data
$result = @mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , horse, temperature, conditions FROM historical_weather ORDER BY date DESC');
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each field in a paragraph
while ( $row = mysql_fetch_array($result) ) {
//$date = date("d M Y",$row["date"]);
$table_row = "<tr align=\"center\" valign=\"middle\">";
$table_row .= "<td WIDTH=22%><font size=\"3\"><font face=\"arial\">$row[formattedDate]</td>";
$table_row .= "<td WIDTH=13%><font size=\"3\"><font face=\"arial\">$row[horse]</td>";
$table_row .= "<td WIDTH=21%><font size=\"3\"><font face=\"arial\">$row[temperature]</td>";
$table_row .= "<td WIDTH=13%><font size=\"3\"><font face=\"arial\">$row[conditions]</td>";
echo "$table_row\n";
Do you see anything wrong with this code?
Thanks.
jls
if that's all your code, you're missing the } to finish the while loop.
The array keys should probably be enclosed with 's, and to display the degree-sign next to the temperature:
echo $row['temperature'].'& #176;';
(remove the space after the &)
(enclosing code with php tags makes it easier to help you)
jlsohio
02-06-2006, 11:38 PM
<?php
include("connect.php");
?>
<?
//Begin your table outside of the array
echo "<table border=1 cellpadding=2 cellspacing=0 bordercolorlight=brown bordercolordark=brown bgcolor=ffffff width=95%>\n";
$table_row = "<tr align=\"center\" valign=\"middle\">";
$table_row .= "<th><font size=\"4\"><font face=\"arial\">Jug Winner</u></th>";
$table_row .= "<th><font size=\"4\"><font face=\"arial\">Date</u></th>";
$table_row .= "<th><font size=\"4\"><font face=\"arial\">Temperature</u></th>";
$table_row .= "<th><font size=\"4\"><font face=\"arial\">Conditions</u></th>";
echo "$table_row\n";
// Request the text of all the data
$result = mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , horse, temperature, conditions FROM historical_weather ORDER BY date DESC');
if (!$result) {
die('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each field
while ( $row = mysql_fetch_array($result) ) {
//$date = date("d M Y",$row["date"]);
$table_row = "<tr align=\"center\" valign=\"middle\">";
$table_row .= "<td WIDTH=22%><font size=\"3\"><font face=\"arial\">$row[formattedDate]</td>";
$table_row .= "<td WIDTH=13%><font size=\"3\"><font face=\"arial\">$row[horse]</td>";
$table_row .= "<td WIDTH=21%><font size=\"3\"><font face=\"arial\">$row[temperature].'& #176;'</td>";
$table_row .= "<td WIDTH=13%><font size=\"3\"><font face=\"arial\">$row[conditions]</td>";
echo "$table_row\n";
}
?>
Here's the error I'm getting:
Parse error: parse error, unexpected T_STRING in historical_weather.php on line 35
Line 35& 36 is this:
while ( $row = mysql_fetch_array($result) ) {
//$date = date("d M Y",$row["date"]);
I haven't even gotten to the temperature formatting yet.
What I'm I doing wrong here?
Thank you for your help.
jls
vinyl-junkie
02-07-2006, 03:29 AM
Change this:
$result = mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , horse, temperature, conditions FROM historical_weather ORDER BY date DESC');
to this:
$result = mysql_query("SELECT DATE_FORMAT(date, '%m-%d-%y') AS formattedDate , horse, temperature, conditions FROM historical_weather ORDER BY date DESC");
jlsohio
02-07-2006, 06:23 PM
Good catch! It worked. Thank you.
Now I'm still having a problem displaying the degree sign.
Here's the line I think is wrong:
$table_row .= "<td WIDTH=21%><font size=\"3\"><font face=\"arial\">$row[temperature].'& #176;'</td>";
Thanks again for your help & patience.
jls
Mhtml
02-07-2006, 06:40 PM
& #176 should be °
jlsohio
02-07-2006, 07:01 PM
Got it. Thanks.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.