0

hi
I need to display date which is stored in database and need to format and display on web page the current format is (Y-m-d)
I need to display as (d-m-Y);
On the web page pls anybody help me with the php script I will paste my code:

<?php
$d=$_POST['sdd'];
$m=$_POST['sdm'];
$y=$_POST['sdy'];
$string=date("Y/m/d",mktime(0,0,0,$m,$d,$y));
$con=mysql_connect("localhost","root","");
	if(!$con)
	{
		die('UNABLE TO CONNECT TO DATABASE'.mysql_error());
	}
	mysql_select_db("dummy");
	//echo $string; 
	mysql_query("insert into date1 (datevalue, count) values ('$string' , ' ')");
	$result=mysql_query("select date_format( datevalue , ' %d/ %m/ %Y ' ) as date  from date1 order by count desc");
	if($row=mysql_fetch_array($result))
	{
		echo "Welcome user u selected the following date";
		echo "<br>";
		echo $row['datevalue']; 
		echo "<br>";
		echo "Done displaying date";
	}
	mysql_close($con);
	
?>

but it isnt displaying anything

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

5
Contributors
4
Replies
20
Views
9 Years
Discussion Span
Last Post by antonyruban
0

Use the code below, edit all the red text with correct data.

<?php
$db_host = 'HOST';
$db_user = 'USER';
$db_pwd = 'PASS';

$database = 'DB';
$table = 'TABLE';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

// sending query
$result = mysql_query("SELECT 
  `TABLE`.FIELDNAME(DAY),`TABLE`.FIELDNAME(MONTH),`TABLE`.`FIELDNAME(YEAR)`
FROM
  `TABLE`
LIMIT 0 , 30");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<table border='0'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>

Save as PHP, if html phasing isn't enabled. Data should appear, In the correct format you wish.

If this information was helpful. Please add to my rep. Thanks

Edited by Ezzaral: Added code tags.

0

hi
I need to display date which is stored in database and need to format and display on web page the current format is (Y-m-d)
I need to display as (d-m-Y);
On the web page pls anybody help me with the php script I will paste my code:

<?php
$d=$_POST['sdd'];
$m=$_POST['sdm'];
$y=$_POST['sdy'];
$string=date("Y/m/d",mktime(0,0,0,$m,$d,$y));
$con=mysql_connect("localhost","root","");
    if(!$con)
    {
        die('UNABLE TO CONNECT TO DATABASE'.mysql_error());
    }
    mysql_select_db("dummy");
    //echo $string; 
    mysql_query("insert into date1 (datevalue, count) values ('$string' , ' ')");
    $result=mysql_query("select date_format( datevalue , ' %d/ %m/ %Y ' ) as date  from date1 order by count desc");
    if($row=mysql_fetch_array($result))
    {
        echo "Welcome user u selected the following date";
        echo "<br>";
        echo $row['datevalue']; 
        echo "<br>";
        echo "Done displaying date";
    }
    mysql_close($con);

?>

but it isnt displaying anything

can you change you AS DATE i think DATE() is a reserved function in MYSQL you use DATE as an ALIAS.

Edited by mike_2000_17: Fixed formatting

0

I just wanted to say, I was looking for an answer to this same question, and this post helped me a great deal.

Thanks!

0
$table=date,field name=date1,date2 , datatype=datetime

$sql="select date1 from date;
$result=mysql_query($sql) or die(mysql_error());
if($row=mysql_fetch_array($result))
   {
      $cr_date=date_create($row['date1']);
      $for_date=date_format($cr_date,'d-m-Y H:i:s');
   }
print $for_date;

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.