Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP: convert number to a word

New Here ,
Mar 14, 2012 Mar 14, 2012

This is my page, I am trying to get the month which shows up as 12 to be DEC , I have connect to the database but I am stuck after than any help will be much appreciate. 

THE DATA THAT IS OUTPUT IS AT THE BOTTOM OF THE CODE.

<?php require_once('../Connections/event.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

mysql_select_db($database_event, $event);

$query_Recordset1 = "SELECT `month`, `day`, `year` FROM events";

$Recordset1 = mysql_query($query_Recordset1, $event) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

<body>

<?php echo $row_Recordset1['month']; ?><br />

<?php echo $row_Recordset1['day']; ?><br>

<?php echo $row_Recordset1['year']; ?>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

<br />

12 ( I WANT THIS TO DISPLAY AS DEC)

31

2012

this is the structure of my month field

month     varchar(2)     latin1_swedish_ci         No     None   

TOPICS
Server side applications
598
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 14, 2012 Mar 14, 2012

http://stackoverflow.com/questions/3283550/convert-month-from-name-to-number

Personally, I'd just store a timestamp when you insert the date so that you can just use the PHP date function to output however you want.  But this is an alternative method if you just have the number and want to convert.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2012 Mar 14, 2012
LATEST

>Personally, I'd just store a timestamp when you insert

>the date so that you can just use the PHP date function

>to output however you want.

Absolutely! Why would you ever want to store a date a separate text fields in a database?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines