Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Displaying Date From A Database


All I need to do is change the date so it reads, for example, May 1999 when it's displayed on the page. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Reading And Displaying A Date From A MySql Database
I've just started using php, and although I am very impressed by it,
there are some things with which I am confounded!

What I'm trying to do is read in a Date from a mySql database and then
display it on screen (the Date is in the usual yyyy-mm-dd format).

If I use SQL on phpadmin
SELECT Date
FROM details
WHERE details.Name = "Paul Lee"
LIMIT 0 , 30

The result comes up 2005-01-01, so this seems to work.
But if I use the following:

$db = mysqli_connect("localhost","root","");
@mysqli_select_db($db, "personnel") or die ( "Unable to select
database" );
$query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee"
LIMIT 0, 30'

$result=mysqli_query($db, $query);

echo "<br>";

echo $result;

mysqli_close($db);

I get "Object id #2" displayed on screen.
I have tried to use the explode function to separate the months, year
and day using the "-" as a delimeter, but this doesn't work, and I
can't seem to get the other php date/time functions to work either.

Help With Displaying Selecting A Date Range And Displaying Results
I wish to create a simple form that allows the selection of a start date and a stop date with the ability to select what columns to be displayed in the result page.

Date Is Not Being Pulled From MYSQL Database, Instead Current Date Is Displayed!
I am having trouble pulling a date from a database using PHP at the <a
href="http://www.mytuneslive.com/ameshkin69/"> following page.</a>

Here is the code. As you can see, it is just making the date the
current time. The values in the database are UNIX timestamp, and the
DATE() function is used to convert from UNIX to readable date. Can

<td width="55%" align="left" valign="top"><?php
$row_comment['timestamp'] = date("n d Y g:i A");.....

Displaying Date
i'm working on K Yank's book and, at some point, i've an insert like this:

$sql = "INSERT INTO Jokes SET
...
JokeDate = CURDATE()";

When i dysplay this on my webpage, the date format is YYYY,MM,DD
and in my country (Portugal), the format is day, month, year
How can i achieve it?

Displaying Date...
As a final touch to my current project I am trying to display a "Last Updated: " field on the user profile pages of the website. The SQL database is updating the field last_updated automatically any time a record is altered, and this is working fine...

Structure details from phpMyAdmin (in table 'users'): last_updated timestamp  ON UPDATE CURRENT_TIMESTAMP No 0000-00-00 00:00:00

However when I try to output this date I get the result:

Profile Updated: January 1, 1970

The code I am using is as follows... Code:

Displaying A Date
My current code:

foreach ($page['events'] as $z) {

echo '<b>', $z['date'],  '</b></p>';

}

Which is pulling "date" from a DATE field in the database. Would like it to display as 3-22-2007 ... instead of 2007-3-22 - I know theres a quick answer out there but cant find it.

Displaying A Date Range
I would like to display a user specified date range e.g Monday to Monday next week or maybe Monday next month. When I have the basic function worked out I would like to get Data from a Mysql Database. here is what I have thought about. Code:

Displaying A Date With Strtotime
I have successfully used strtotime to format the date on a webpage that is
pulled form a MySQL database in the form yyyy-mm-dd.

However, in another part of the webpage, I have to insert another date that
may contain a NULL entry in the database. If I use strtotime to format this
then it enters the current date, whereas I want it left blank.

Displaying The Date In A Different Format!
I have a row called Date in the databse which is saved as 0000-00-00 When I try to echo it, it shows like that 2007-04-16 Maybe because I use this normal code: echo $row['Date']; How can I display it like that:16-04-2007

Displaying Date/time
I'm trying to display a datetime type which I save with NOW()

ie:
    // create query
    $query = "INSERT INTO purchase (category, location, price, time) VALUES ('$category', '$location', '$price', NOW())";
time is a datetime type

I want to just display the "time" part of time,  not the date

this is the code I'm using:
echo "<li><a href=".$_SERVER['PHP_SELF']."?category=".$row[5].">".date("G.i:s", $row[5]."</li>";
and getting a "Parse error: syntax error, unexpected ';' ..."

Displaying Modified Date Of A URL File
I want to display a web page with links to various documents and display the date each document was last modified next to the link. I've found the filemtime command and that works quite nicely for "local" files. However, filemtime doesn't work if the file(s) are refered to by their URLs (which is how I need to do it).

A comment on the manual page (http://www.php.net/manual/function.filemtime.php3) refers to having to use "Socket Operations" but the link posted with that comment doesn't work (it just goes to a page saying the website has been rearranged).

Date/time Displaying Wrong
How do I set the time display to echo the time, in the timezone the user is in and not the server time. For somereason im in eastern timezone and the host server i9s in central and the time displayed on my laptop is in central.

Displaying 'new' Icon Based On Date?
I'd like to display a little "new" icon next to all products in a directory which are, funnily enough, new! I've got a date (timestamp) for each product which is inserted on adding a new product and updating a product.

I'd like to do a conditional region using the timestamo but I'm not sure what to use - I could do === [current date] but that would only show the icon for that day and I'd like it to be there for about a week or so.

Displaying Local Date In Specific Format
i'm trying to decide whether to use PHP or JavaScript to display a date on a website. what i'm wondering is where does PHP take the date from, the server or the client (ie will timezone become a factor). aswell as this, is there a simple way to allow the date to be displayed as: "22nd" "1st" or "14th" instead of "22" "1" or "14"?

Displaying From Database!
I'm trying to display products that are pulled form a database in a certain way using only DIV tags I would like the products to display across the page in rows of 4, however when i use div tags it is just putting one on each row.. whats the best way to display in a row of 4? here is an example script of what im using to experiment with: Code:

Not Displaying First Record In Database
this code is not showing up first record in database:
the table should start off by clan id = 1 and clan name = name1
page: PHP Code:

Displaying Content From Database
need some simple help with displaying content from a mySQL database using PHP. i want to know how to write a php script to display the latest entry in a table to an html page. and also how to adapt the script to display the latest x amount of entries.

Problem Displaying Image From Database
I used the code below to pull out an image from a mysql database
but nothing shows on the page and there was no error message to
indicate any problem.What could be wrong.The image is actually in the
database with all the details:

<?php
if(isset($_GET[loginid]))
{
$con=mysql_connect("localhost","name","pass");
if(!$con)
{
die('Could not connect to database:'.mysql_error());
}
mysql_select_db("datab",$con);
$id = $_GET[loginid];
$query = "SELECT name, type, size, content " .
"FROM image WHERE id= '$id'";
$result = mysql_query($query) or die('Error, query failed');
$file=mysql_fetch_array($result);
$name=$file['name'];
$type=$file['type'];
$content=$file['content'];
header('Content-length: '.strlen($content));
header("Content-type: $type");
header("Content-Disposition: inline; filename=$name");
echo $content;
}
mysql_close($con)
?>

Displaying Values From A Database From An Include
I've got a URL going to a template, e.g. www.mydomain.com/product.php?id=product_a

where the template is product.php the tag after the ? refers to the product that should be displyed in the template, in this case product_a

Inside the template (product.php) I've got:-

<? $url = $id.".htm"; include("$url"); ?>

This works fine so far. How ever I've also got an include inside the the template (product_a.php), called product_info.php, which is another php file that displays the product version and the platforms that it sits on. so in the the include (product_info.php) I have:-

<?php

$db = mysql_connect("localhost", "username", "password");
mysql_select_db("DATABASE",$db);
$result = mysql_query("SELECT version FROM table1 WHERE id = id",$db);

do { if ($myrow[0] != "") { echo "$myrow[0]n"; } }

while ($myrow = mysql_fetch_array($result));?>

however this displays all the version numbers within the table (for every product)

I just want it to display the version number of the value of $id (www.mydomain.com/product.php?id=product_a)

Displaying Image Stored In Database
The user can browse and upload an image and the image is stored successfully in a seperate binary table (with userid and bin_data, filesize, filename, filetype). The photo is displayed properly when I point my broswer to a script called fileshow.php:
PHP Code:

Problem Displaying One Column Of One Row From A Database With PHP.
I have a small script with PHP that queries a MySQL database to pull
out one row, where I want to be able to access each of the columns
separately. I have tried several different variations and am able to
get the entire row to print, but when I attempt to access the
individual columns I get an error. Here is what I have so far:

if (isset($_POST['memberNo'])):
$link = mysql_connect('...','...','...');
mysql_select_db("...");

//Perform a test query
$query = "SELECT * FROM users WHERE 'id' = " . $_POST['memberNo'];
$result = mysql_query($query) or die(mysql_error());

$line = mysql_fetch_assoc($result);
print $line;

//Close connection
mysql_close($link);

The point of this code is to retrieve the user information to validate
the login information sent in the previous form. I do not get an
error with this code, but it also does not print anything. I know
there is an entry in the database that matches data sent in the
$_POST['memberNo'] variable, it is the only entry in the database.

Changing the 'print $line;' to 'print $line["id"];' does not display
anyting either.

Displaying Database And Getting Unwanted Results...
I want to display everyone in the database, but only if the 'level' field is larger than 0.  Well, this works fine for most of the database... but if the last entry in the database is 0, then it prints it anyways.

Is there anyway around this?  I tried adding an if statement before the last bit where I echo out the table rows, but it was killing the entire table, or still showing the same results. Code:

Displaying Results From Database In A Particular Format
How do I display results from a database in a particular format.  For example the following text in this format including the lines in stored in the database:

Quote“Hello,

Welcome to the news for 11/06/07.

Thanks”
When I echo the results using the usual, <? echo $row_news[‘news’]; ?> it doesn’t echo the information in the database in the format it is stored for example it will display like this.  Quote“Hello, Welcome to the news for 11/06/07. Thanks”  How do I get it to display in the format it in displayed in the database?

Displaying Database Information In Columns
I have a database with products in and I want iT to automatically show every product on the page. Now I am able to do this easy enough but what I am struggling to do is that I want the products to be displayed in 3 columns. I can get them to display one under the other easy enough but I want them to be in rows with 3 columns instead.

Displaying Multiple Items From Database
what i have is a page that has four sections. what i want to have is when the page opens, in that page i want the lastest two items for each section from a database to be displayed. the items to be displayed are an image, a title and a description. but i also want the description to be shortend to say about 25-30 words or about 100 chars, if thats easier?

so in the end i have 4 sections, each showing the lastest two items for each section.

would the best way to do this be to have a seperate table in the database for each of the sections? or would i be able to do it from one table?

would i have to creat a query for each of the sections?
e.g:
SELECT * FROM table WHERE section=section

Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}

Displaying Information From A Database In A Text Field,
I am trying to create an admin page, but before I get anywhere near that, I need to understand how to get data froma database to show up in appropriate form fields *text, textarea, etc...*

I am able to get content from my database to show up in my template, now I want to create a page that allows a user to click on a link for which they want to edit the information (name, and bio) So I want that page to show up with a simple form, a text field displaying the name, and a textarea displaying the bio information, so that they can modify it and save it to the database. how do you get the information to show up in the form fields? Code:

Displaying Database Records Over Multiple Columns
I am currently using the following to generate a table with a single column with ten entries PHP Code:

Previous And Next Links And Displaying Database Information
I would like to display a listing of files on a web page as follows:

If there is only one file: display the section name and then display the
current file.

If there is more than one file (for the first page): display the section
name, the current file and a few archive files.

If there is more than a page full (for each additional page): display the
section name, and the next set of archive files.

This is the code I have been working with (it's a bit ugly, suggestions are
welcome). For some reason the second page of listings skips the first item.
1st page lists items 0 through 4, second page skips item 5 and starts
displaying item 6.

function display_table($sec_id, $num_item){
GLOBAL $link;
$updir = "../uploads/"; //maybe this should be a GLOBAL variable???
if (isset($_GET['start'])){$start = $_GET['start'];}else{$start = 0;}
//GLOBAL $start;
//query DB
$query_total = "SELECT file_id
FROM files
WHERE file_section_id =" . $sec_id ;
$query = "SELECT file_id, file_meeting_date, file_meeting_time,
file_title, file_modified, file_section_id, sec_name, sec_id,
sec_disp_archive
FROM files f, section s
WHERE f.file_section_id =" . $sec_id . " AND f.file_section_id = s.sec_id
ORDER BY file_modified DESC LIMIT " . $start . "," . $num_item;
$result = mysqli_query( $link, $query ) or die(mysqli_error($link));
$result_total = mysqli_query( $link, $query_total ) or
die(mysqli_error($link));
$num_rows = mysqli_num_rows($result_total);
//print $query;
//create hyperlinks and display table
//display current file
/* print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " .
$num_rows;*/
/*$obj = mysqli_fetch_object($result);*/
if ($num_rows > 1){ //Display current and archive files
//only display current table if start is not set (not on page 1)
$obj = mysqli_fetch_object($result);//Call DB
$content = "<div id ='MainContent'><p><b>" . $obj->sec_name .
"</b></p><table width=ď`%' border=&#391;'>";
if (!isset($_GET['start'])||$_GET['start']==0){
//for 1st item display file info
$content.= "<tr><td colspan=&#393;' align='center'>Current</td></tr>";
$content.= "<tr bgcolor='#CCCCCC'><td width=&#3933;%'>Meeting Date</td><td
width=&#3933;%'>Meeting Time</td><td width=&#3934;%'>File</td></tr>";
$content .= "<tr><td>" . date("F jS,
Y",strtotime($obj->file_meeting_date)) . "</td><td>" . date("g:i
A",strtotime($obj->file_meeting_time)) . "</td><td><a href='" . $updir .
$obj->file_title . "'>" . "View Current File" . "</td><tr>";
$content .="</table>";
print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " . $num_rows;
//DEBUG

Displaying Block Of Text From MySQL Database
I would like to create a details.php page that displays all my products. I understand how to get the title, price, description etc from mySQL. But my problem is how do I get a list of data? For example say I want to display the features of a product in point form (list). What is the best way to do this? How do most common websites do this? Code:

Limit A Database Field To Displaying Only One Time And Still Display All?
I have a data table with a field that contains the exact same text (example "some text") on several different rows. How can I display all my rows without getting duplicates of this field; I only want to display this field once. I tried to use a LIMIT, but this is not what I needed. Code:

Displaying Data From Mysql Database In A Drop Down List On Form.
I'm trying to do is display data from two different mysql tables from the same database in a drop down list on a html form. I have a fixtures table with the player1(userid), player2(userid), gameid, game, score1 and 2, what I want is to use the userid to get the players first name and surname from the members table (as it is a unique id), I need to do this bit before displaying it in the drop down. I think i need 2 querys to do this but when I have tried it it just echo's a blank value or the userid not the forname and surname that I want. I'm using the fetch_array function but just can't see where I'm going wrong, Code:

DATE Doesn't Get Into Database
I have a HTML-form with a 10width field in which you can enter a date. But whatever I enter. In the database I always find 0000-00-00. The variable comes through. I checked that. Does anybody know what I do wrong ?

Date Database?
The admin assistants can enter the number of hours that each employee has worked on a particular date in a particular month (hours are variable depending upon customer demand) and at the end of the month need to run off a pay slip for each employee containing the following data:

I know how to add, delete and modify the data, the only thing im not sure of is the databse structure for the dates.

Inserting Date Into Database
I have a pretty simple news code that inserts the data, and then is retreaved, with a pretty simple scheme. I have a date column set at timestamp(14), and I'm trying to insert NOW() as the date. I browse with phpmyadmin and all it has is 14 zero's. PHP Code:

Inserting Date In Database
I have form which allows a user to select a date as part of the form.
On submitting i am getting no update to the database and no error message.
To try and test it i created a shorter version which sets up the variables except the date.This gives the same result.ie no update. Code:

Filtering Results By DATE Value In Database
I have this code in my page for displaying some data from a database, sorted by date. i had posted a messed up version of this a while ago but I couldnt get it working even after a few suggestions. PHP Code:

What Is The Proper Date Format For A Txt Database?
I would like to know what format should be used when writing to a txt file. I am trying to search between a start date and a ending date and list any variables For example.

if (($sDate <= $jdate && $eDate >= $jdate))

then I have it list the variables it will work if searching between months and days but it does not work if I have different years. I will get all years printed out.

my date format is m/d/Y 6/13/2001

If I search for example start date = 6/01/2001 and the ending date = 6/09/2001

I will get the correct month and day dates but I also get anything from the year before and including year in the future.

Date & Time Format In Database.
I'm using MySQL database, the problem is I've setup that user input the Date format in dd/mm/yyyy (example: 14may2007) and Time (example: 12:00pm). How do I convert it to Date & Time format in database format before insert into database? Sorry, noob here.

Calculating Dates From A Date In The Database?
I`m using this format of dates:

$entry_date = strftime("%B %e, %Y %H:%M:%S", time());
And that time gets saved into the database (birth in ownedpets database):

$res = mysql_query("SELECT id, owner, pet_type, pet_name, birth, food, play, datetime FROM ownedpets WHERE id=$id");
$rows = mysql_fetch_row($res);
mysql_free_result($res);

So let`s say in this case, the database birth value ($rows[4]) is October 19 2007 20:00:00. What do I do to tell php to check to see if the current date (hours and all don`t matter) is 21 days after the $rows[4]?

Why I`m looking for this task:
For the pets system, if the pet is 21 days after it`s birth, it will be an adult. But if it is not 21 days after it`s birth, it will still be a baby.

Today's Date In Database Insertion
How do I insert today's date in a certain database row without using the date() function for a string?  For example, when you use PHPMyAdmin to insert a new table row and there's a column with the type "date", it gives you options such as CURDATE, NOW, etc.  How would I use that in a database query?

Convert Date From A Database Query
I have a simple database for events. I have a column named "date" that I would like to display as "March 8, 2007" on the webpage. What do I need to add to change the date format? Here is my php code:

Inserting A Date Into A Microsoft Access 97 Database
I was wondering if anyone could help me insert a short date into microsoft access 97 using php? i can insert text no problem but i can't seem to be able to insert a date properly. i have been using

//$date = "#" . "$sqlmonth" . "1" . "$cboyear" . "#";

$strSQL = "INSERT INTO tblSupport (tDate) VALUES ($date)";
$result = odbc_exec($connect, $strSQL);

Note: i can insert a date if i hard code it like putting in #01

How To Find The Last Accessed Date Of A MySql Database
How to find out the last accessed date of a MySql Database. I have around 200 databases in my server some are used and some are not in Use, I want to remove the database that are not in Use. SHOW TABLE STATUAS gives me last updated Date. In my case there are some database which are not updated at all, but...

Insert Server Date / Time Into Database
I currently have the following to insert a variable into a database:

$zip = $db->escape($_POST['zip']);
$db->query("INSERT INTO zip SET zips = '$zip'");

I would like to also add the date & time the submission was made.

Pulling Data From A MySQL Database With PHP Date Code??
I am trying to find ways to retrieve data by date from a mysql database.
What I would like to do is to have the option for people to retrieve a file
that was entered in the week before the current day (something like click
here for all drinks added in the last week) I have tried to make this code
work, the only way I can is to manually change the date every day, I would
like it to do it automatically.

Taking Date Of Birth From User And Sending It To A Mysql Database
i have created a form that takes a users date of birth as 3 seperate values $day $month and $year i do not know how to combine these values into a single value called $dob.
I tries using just a singal value to take the date however it did not work, even after I had formated my database.

Convert User Entered Date And Time To Unix Timestamp Before Inserting To Database
How do you convert a user inputted date to a unix timestamp before
insterting it into your database? I have a form, with a textfield for
a date that the user inputs in the format mm-dd-yyyy and three dropdow
boxes for hours, minutes, and AM/PM. All of these need to be considered
together and converted to one Unix Timestamp and then inserted to the
MYSQL date field. The type of field is INT (11) so that I can instead
of the standard 0000-00-00 format of MYSQL so that I can do better
calculations and queries.

Sort Results By Date/time, Limit 5 Database Entries Of Today &/or Upcoming Days
I'm designing a website for my fraternity and in the database I have entries which contain past events, todays events, and upcoming events.  My problem is that I can not figure out how to sort the query results to display:
 
1) only past events based on the CURRENT DATE
2) only the events which fall on the CURRENT DATE or after, limiting the results to 5 entries
3) all events that fall on CURRENT DATE or afterwards

Example:   
Today is  September 15, 2007

Problem 1) Displaying all events that happened before September 15, 2007
Problem 2) Displaying only 5 results that fall on September 15, 2007 or after
Problem 3) Displaying all events that are happening on or after September 15, 2007

And obviously I would like the CURRENT DATE to change depending on what date it is, currently.

Ok so now I've been very redundant in my explanation of my problem here is the code and a link to what that particular page looks like. Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved