[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php add current time to row

Posted on 2010-01-07
4
Medium Priority
?
258 Views
Last Modified: 2012-05-08
this php
prints to csv

i want to add column 'current time'
fputcsv($fp, array($p['folderid'], $p['name']) );

so

fputcsv($fp, 'current time' ,array($p['folderid'], $p['name']) );
?php
require_once('../common.php');    
$sql = "SELECT * FROM productfolders WHERE active = '1' ORDER BY name"; 
$products = dbfetcharray($sql); 
$fp = fopen('file.csv', 'w'); 
foreach($products as $p){
fputcsv($fp, array($p['folderid'], $p['name']) );
} 
fclose($fp); 
?>

Open in new window

0
Comment
Question by:rgb192
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 26203231

$currentTime = date("H:i.s"):

fputcsv($fp, $currentTime ,array($p['folderid'], $p['name']) );

The options for setting date() are at http://www.php.net/date so if you wanted the date as part of the current time

$currentTime = date("Y-m-d H:i.s"):
0
 

Author Comment

by:rgb192
ID: 26203719
fputcsv($fp, $currentTime ,array($p['folderid'], $p['name']) );

line doesnt work
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 26203792
Oops...

fputcsv($fp, array( $currentTime, $p['folderid'], $p['name']) );

I've put it on the start of the existing fields but you can move it wherever you wish - just keep it in the array
0
 

Author Closing Comment

by:rgb192
ID: 31674179
works
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question