| | |
retrieve date from database to display on web page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2006
Posts: 13
Reputation:
Solved Threads: 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
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
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
<?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
Last edited by macneato; Jun 20th, 2007 at 9:19 am.
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
•
•
•
•
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.
Last edited by rm_daniweb; Apr 9th, 2009 at 6:13 am.
![]() |
Similar Threads
- how to make animation bar in vb.net (ASP.NET)
- how to retrieve the Microsoft Access DAtabase from the INternet using web services (VB.NET)
- Login and retrieve user data from database (ASP.NET)
- displaying data onto a web page (ASP.NET)
- How to display TIFF file on web page? (PHP)
- Use of Image control on Web Page (ASP.NET)
- HTML4 , web page do not display few characters(soft hyphen), Marathi(LangscapeDevpooj (ASP)
- Dynamic web page for multilingual (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Help with some loops and SQL
- Next Thread: Paged content from database
Views: 8332 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox chrelad class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php phpmyadmin problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube





