I'm using getcsv to import csv into database.I have huge number of datasheets in csv format. Currently i'm importing a csv which has 53,000 rows and 35 columns. when i decerase columns it's importing approx all the rows in database, but it's not importing when i want to import all the columns of csv into mysql table.
my csv has all type of character like char,numbers, symbols,specila charaters etc
Please look at my code:
Index.php:
<form action="upload.php" method="post" enctype="multipart/form-data"> <input type="text" name="type2" Placeholder='Type Folder Name' required > <input type="file" name="csv">
<input type="submit" name="submit" value="Import" class="btn btn-success waves-effect waves-light"/>
</form>
UPLOAD.php
<script>
//Declaration of function that will insert data into database
function senddata(filename){
var file = filename;
$.ajax({
type: "POST",
url: "senddata.php",
data: {file},
async: true,
success: function(html){
$("#result").html(html);
}
})
}
</script>
$csv = array();
$batchsize = 1000; //split huge CSV file by 1,000, you can modify this based on your needs
if($_FILES['csv']['error'] == 0){
$name = $_FILES['csv']['name'];
$ext = explode('.', $_FILES['csv']['name']);
$file_ext=strtolower(end($ext));
$tmpName = $_FILES['csv']['tmp_name'];
if($file_ext === 'csv'){ //check if uploaded file is of CSV format
if(($handle = fopen($tmpName, 'r')) !== FALSE) {
set_time_limit(0);
$row = 0;
while(($data = fgetcsv($handle)) !== FALSE) {
$col_count = count($data);
//splitting of CSV file :
if ($row % $batchsize == 0):
$file = fopen("minpoints$row.csv","r");
endif;
$csv[$row]['pno'] = $data[0];
$csv[$row]['area'] = $data[1];
$csv[$row]['project'] = $data[2];
$csv[$row]['flatno'] = $data[3];
$csv[$row]['balcony'] = $data[4];
$csv[$row]['parking'] = $data[5];
$csv[$row]['common_area'] = $data[6];
$csv[$row]['floor'] = $data[7];
$csv[$row]['rooms'] = $data[8];
$csv[$row]['shop'] = $data[9];
$csv[$row]['flats'] = $data[10];
$csv[$row]['offices'] = $data[11];
$csv[$row]['category'] = $data[12];
$csv[$row]['total_area'] = $data[13];
$csv[$row]['plot_no'] = $data[14];
$csv[$row]['emirates'] = $data[15];
$csv[$row]['name'] = $data[16];
$csv[$row]['area_owned'] = $data[17];
$csv[$row]['address'] = $data[18];
$csv[$row]['phone'] = $data[19];
$csv[$row]['email'] = $data[20];
$csv[$row]['fax'] = $data[21];
$csv[$row]['pobox'] = $data[22];
$csv[$row]['gender'] = $data[23];
$csv[$row]['dob'] = $data[24];
$csv[$row]['mobile'] = $data[25];
$csv[$row]['smobile'] = $data[26];
$csv[$row]['passport'] = $data[27];
$csv[$row]['issue_date'] = $data[28];
$csv[$row]['expiry_date'] = $data[29];
$csv[$row]['poissue'] = $data[30];
$csv[$row]['emirates_no'] = $data[31];
$csv[$row]['emirates_exp'] = $data[32];
$csv[$row]['residence'] = $data[33];
$csv[$row]['nationality'] = $data[34];
$csv[$row]['type2'] = $_POST['type2'];
$min = $data[0];
$points = $data[1];
$points2 = $data[2];
$points3 = $data[3];
$points4 = $data[4];
$points5 = $data[5];
$points6 = $data[6];
$points7 = $data[7];
$points8 = $data[8];
$points9 = $data[9];
$points10 = $data[10];
$points11 = $data[11];
$points12 = $data[12];
$points13 = $data[13];
$points14 = $data[14];
$points15 = $data[15];
$points16 = $data[16];
$points17 = $data[17];
$points18 = $data[18];
$points19 = $data[19];
$points20 = $data[20];
$points21 = $data[21];
$points22 = $data[22];
$points23 = $data[23];
$points24 = $data[24];
$points25 = $data[25];
$points26 = $data[26];
$points27 = $data[27];
$points28 = $data[28];
$points29 = $data[29];
$points30 = $data[30];
$points31 = $data[31];
$points32 = $data[32];
$points33 = $data[33];
$points34 = $data[34];
$points35 = $_POST['type2'];
$json = "'$min', '$points', '$points2','$points3','$points4','$points5','$points6','$points7','$points8','$points9','$points10','$points11' ,'$points12','$points13' ,'$points14','$points15','$points16','$points17','$points18','$points19','$points20','$points21','$points22','$points23','$points24','$points25','$points26','$points27','$points28','$points29','$points30','$points31','$points32','$points33','$points34','$points35'";
fwrite($file,$json.PHP_EOL);
//sending the splitted CSV files, batch by batch...
if ($row % $batchsize == 0):
echo "<script> senddata('minpoints$row.csv'); </script>";
endif;
$row++;
}
fclose($file);
fclose($handle);
}
}
else
{
echo "Only CSV files are allowed.";
}
//alert once done.
echo "<script> alert('Data imported!');</script>";
}
Senddata.php
include('connect.php');
$csvMimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain');
$data = $_POST['file'];
$handle = fopen($data, 'r');
$test = file_get_contents($data , $csvMimes);
if ($handle) {
$counter = 0;
//instead of executing query one by one,
//let us prepare 1 SQL query that will insert all values from the batch
$sql ="INSERT INTO imported_property(pno, area, project, flatno, balcony, parking, common_area, floor, rooms, shop, flats, offices, category, total_area, plot_no, emirates, name, area_owned, address, phone, email, fax, pobox, gender, dob, mobile, smobile, passport, issue_date, expiry_date, poissue, emirates_no, emirates_exp, residence, nationality,type2) VALUES ";
while (($line = fgets($handle)) !== false) {
$sql .= "($line),";
$counter++;
}
$sql = substr($sql, 0, strlen($sql) - 1);
if ($conn->query($sql) === TRUE) {
} else {
}
fclose($handle);
} else {
}
//unlink CSV file once already imported to DB to clear directory
unlink($data);
Related
I have a problem here. I don't know how to give an appropriate question title. So here is my problem.
I have a set of csv data. Let's say 30 data. The condition is I want only 20 data goes to Table A and another 10 data goes to Table B.
Do you have any example on how to work with this logic? Can it be done by combining while loop and if statement? By the way, it is a PHP and I'm still a newbie programmer. Hopefully someone can help me. Thank you.
Edited:
My current code
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($leftPax > 0)
{
$registrantBean = new z_EventRegistrants();
$registrantBean->last_name = $data[1];
$registrantBean->id_no = $data[0];
$registrantBean->phone_mobile = $data[2];
$registrantBean->email1 = $data[3];
$registrantBean->gender = $data[4];
$registrantBean->date_of_birth = $data[5];
$registrantBean->age = $data[6];
$registrantBean->race = $data[7];
$registrantBean->z_eventregec5erations_ida = $registrationBean->id;
$registrantBean->save();
$count++;
error_log(print_r($_REQUEST['session'], 1));
foreach($_REQUEST['session'] as $aid=>$sid)
{
$attendanceBean = new z_EventAttendances();
$attendanceBean->name = $registrantBean->last_name;
$attendanceBean->z_eventsessions_z_eventattendancesz_eventsessions_ida = $sid;
$attendanceBean->z_eventactivities_z_eventattendances_1z_eventactivities_ida = $aid;
$attendanceBean->z_eventregistrations_z_eventattendancesz_eventregistrations_ida = $registrationBean->id;
$attendanceBean->z_eventregistrants_z_eventattendancesz_eventregistrants_ida = $registrantBean->id;
$attendanceBean->save();
}
}
else
{
$waitlistBean = new z_EventWaitlists();
$waitlistBean->name = $data[1];
$waitlistBean->save();
}
}
What I want, the 20 data will go to z_EventRegistrants and the other 10 will go to z_EventWaitlist.
You need to asked some where in your code if the $count == 20
`
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($leftPax > 0 && $count <= 20)
{
$registrantBean = new z_EventRegistrants();
$registrantBean->last_name = $data[1];
$registrantBean->id_no = $data[0];
$registrantBean->phone_mobile = $data[2];
$registrantBean->email1 = $data[3];
$registrantBean->gender = $data[4];
$registrantBean->date_of_birth = $data[5];
$registrantBean->age = $data[6];
$registrantBean->race = $data[7];
$registrantBean->z_eventregec5erations_ida = $registrationBean->id;
$registrantBean->save();
$count++;
error_log(print_r($_REQUEST['session'], 1));
foreach($_REQUEST['session'] as $aid=>$sid)
{
$attendanceBean = new z_EventAttendances();
$attendanceBean->name = $registrantBean->last_name;
$attendanceBean->z_eventsessions_z_eventattendancesz_eventsessions_ida = $sid;
$attendanceBean->z_eventactivities_z_eventattendances_1z_eventactivities_ida = $aid;
$attendanceBean->z_eventregistrations_z_eventattendancesz_eventregistrations_ida = $registrationBean->id;
$attendanceBean->z_eventregistrants_z_eventattendancesz_eventregistrants_ida = $registrantBean->id;
$attendanceBean->save();
}
}
else
{
$waitlistBean = new z_EventWaitlists();
$waitlistBean->name = $data[1];
$waitlistBean->save();
}
}
}
`
So I am importing data from an .asc file and I am putting it into a database. Everything gets inserted but in the beginning it has a little problem.
This is the code:
<?php
function importdb()
{
include('db_config.php');
$File = 'lijst.csv';
$File2 = 'preise.asc';
$handle = fopen($File, "r");
$handle2 = fopen($File2, "r");
$arrResult = array();
$arrResult2 = array();
fgetcsv($handle);
fgetcsv($handle);
fgetcsv($handle);
fgetcsv($handle);
fgetcsv($handle);
fgetcsv($handle);
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE && ($data2 = fgetcsv($handle2, 1000, ";")) !== FALSE) {
//---------------------
$artikelnmr = $data[0];
$barcode = $data[1];
$omschrijving_nl = $data[2];
$omschrijving_exp = $data[3];
$bruto_prs = $data[4];
$staffel_prs = $data[5];
$aktie_prs = $data[6];
$bruto_antl = $data[8];
$staffel_antl = $data[9];
$aktie_aantal = $data[10];
$voorraad = $data[15];
$leverdatum = $data[16];
$besteld = $data[17];
$pallet_antl = $data[19];
$artikel_groep = $data[22];
$extra_info = $data[27];
//------------------------
$type = $data2[0];
$artikel = $data2[1];
$prijs1 = $data2[6];
$prijs2 = $data2[7];
$prijs3 = $data2[8];
$prijs4 = $data2[9];
$prijs5 = $data2[10];
//----------------------
$stmt = $db->prepare("INSERT INTO `producten`(`id`, `artikelnr`, `barcode`, `omschrijving_nl`, `omschrijving_exp`, `bruto_prijs`, `bruto_aant`, `staffel_prijs`, `staffel_aantal`, `aktie_prijs`, `aktie_aantal`, `voorraad`, `leverdatum`, `besteld`, `pallet_aantal`, `artikel_groep`, `extra`)
VALUES ('', :artikelnmr,:barcode,:omschrijving_nl,:omschrijving_exp,:bruto_prijs,:bruto_aantal,:staffel_prijs,:staffel_aantal,:aktie_prijs,:aktie_aantal,:voorraad,:leverdatum,:besteld,:pallet_aantal,:artikel_groep,:extra)");
$stmt2 = $db->prepare("INSERT INTO `prijzen`(`artikelnr`, `prijs_soort`, `prijs1`, `prijs2`, `prijs3`, `prijs4`, `prijs5`) VALUES (:nmr, :soort, :prijs1, :prijs2, :prijs3, :prijs4, :prijs5)");
//----------------------
$stmt->bindParam(":artikelnmr", $artikelnmr);
$stmt->bindParam(":barcode", $barcode);
$stmt->bindParam(":omschrijving_nl", $omschrijving_nl);
$stmt->bindParam(":omschrijving_exp", $omschrijving_exp);
$stmt->bindParam(":bruto_prijs", $bruto_prs);
$stmt->bindParam(":bruto_aantal", $bruto_antl);
$stmt->bindParam(":staffel_aantal", $staffel_antl);
$stmt->bindParam(":staffel_prijs", $staffel_prs);
$stmt->bindParam(":aktie_aantal", $aktie_aantal);
$stmt->bindParam(":aktie_prijs", $aktie_prs);
$stmt->bindParam(":voorraad", $voorraad);
$stmt->bindParam(":leverdatum", $leverdatum);
$stmt->bindParam(":besteld", $besteld);
$stmt->bindParam(":pallet_aantal", $pallet_antl);
$stmt->bindParam(":artikel_groep", $artikel_groep);
$stmt->bindParam(":extra", $extra_info);
//----------------------
$stmt2->bindParam("nmr", $artikel);
$stmt2->bindParam(":soort", $type);
$stmt2->bindParam(":prijs1", $prijs1);
$stmt2->bindParam(":prijs2", $prijs2);
$stmt2->bindParam(":prijs3", $prijs3);
$stmt2->bindParam(":prijs4", $prijs4);
$stmt2->bindParam(":prijs5", $prijs5);
//----------------------
$stmt2->execute();
$stmt->execute();
echo $artikel . ': ' . $type . "<br>";
}
fclose($handle);
fclose($handle2);
}
importdb();
?>
This only happens in the second statement (stmt2). Everything is okay in the first statement (stmt)
This is what happens in the database and what should be put in the first few lines:
Database Result
What should be inserted
Do I need to skip a few lines just like I did in the first file?
Thanks in advance.
<?php
$row = 0;
$handle = fopen("data20150804.log", "r");
while (!feof($handle) ) {
$line_of_text = fgetcsv($handle, 1024, ",");
$num = count($line_of_text);
$timeStamp = $line_of_text[0];
$visibility = $line_of_text[1];
$pressure = $line_of_text[2];
$rain = $line_of_text[3];
$temperature = $line_of_text[4];
$humidity = $line_of_text[5];
$dewpoint = $line_of_text[6];
$R1windSpeed = $line_of_text[7];
$R1wSpeed3s = $line_of_text[8];
$R1wSpeed2min = $line_of_text[9];
$R1wSpeed10min = $line_of_text[10];
$R1windDirDeg = $line_of_text[11];
$R1wDirDeg3s = $line_of_text[12];
$R1wDirDeg2min = $line_of_text[13];
$R1wDirDeg10min = $line_of_text[14];
$R2windSpeed = $line_of_text[15];
$R2wSpeed3s = $line_of_text[16];
$R2wSpeed2min = $line_of_text[17];
$R2wSpeed10min = $line_of_text[18];
$R2windDirDeg = $line_of_text[19];
$R2wDirDeg3s = $line_of_text[20];
$R2wDirDeg2min = $line_of_text[21];
$R2wDirDeg10min = $line_of_text[22];
$gust = $line_of_text[23];
//$row++;
}
fclose($handle);
?>
my csv file is keeping generate the data in a few second.
I want to remove the last row of the csv because my system is reading the last row data and my last row is blank.
If you check the documentation for fgetcsv you'll see the note about blank line returns. So if you do a check after:
$line_of_text = fgetcsv($handle, 1024, ",");
Along the lines of:
if (count($line_of_text) == 0 || $line_of_text[0] === null) {
continue;
}
This should do what you need.
Try this one
<?php
$row = 0;
$file = new SplFileObject("data20150804.log.csv");
$file->setFlags(SplFileObject::READ_CSV);
$file->setFlags(SplFileObject::SKIP_EMPTY);
foreach ($file as $line_of_text) {
$num = count($line_of_text);
$timeStamp = $line_of_text[0];
$visibility = $line_of_text[1];
$pressure = $line_of_text[2];
$rain = $line_of_text[3];
$temperature = $line_of_text[4];
$humidity = $line_of_text[5];
$dewpoint = $line_of_text[6];
$R1windSpeed = $line_of_text[7];
$R1wSpeed3s = $line_of_text[8];
$R1wSpeed2min = $line_of_text[9];
$R1wSpeed10min = $line_of_text[10];
$R1windDirDeg = $line_of_text[11];
$R1wDirDeg3s = $line_of_text[12];
$R1wDirDeg2min = $line_of_text[13];
$R1wDirDeg10min = $line_of_text[14];
$R2windSpeed = $line_of_text[15];
$R2wSpeed3s = $line_of_text[16];
$R2wSpeed2min = $line_of_text[17];
$R2wSpeed10min = $line_of_text[18];
$R2windDirDeg = $line_of_text[19];
$R2wDirDeg3s = $line_of_text[20];
$R2wDirDeg2min = $line_of_text[21];
$R2wDirDeg10min = $line_of_text[22];
$gust = $line_of_text[23];
}
?>
I hope it will help full for you.
I have the following code to insert records into a database via a csv file
$get_columns = $db_website->prepare("SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'mytable' AND TABLE_NAME = 'products'");
$get_columns->execute();
while ($row = $get_columns->fetch(PDO::FETCH_ASSOC)) {
$want[] = $row['COLUMN_NAME'];
}
$file = fopen($_FILES['filename']['tmp_name'], "r");
$counter = 0;
while (!feof($file)) {
if ($counter === 1)
break;
$have = fgetcsv ($file, 5000);
++$counter;
}
fclose ($file);
$map = array_intersect($have, $want);
$num_feilds = implode($map);
$fields = "`".implode("`,`",$map)."`";
if ($num_feilds != '') {
$file = fopen($_FILES['filename']['tmp_name'], "r");
$line = fgetcsv($file, 1000, ",");
while (($line = fgetcsv($file)) !== FALSE) {
$data = array_intersect_key($line, $map);
$implode = str_replace("'", ''', $data);
$implode = str_replace("£", '£', $implode);
$implode = "'".implode("','",$implode)."'";
$query = $db_website->prepare("SELECT p.stock_id
FROM products AS p
WHERE p.stock_id = :data");
$query->bindValue(':data', $data[0], PDO::PARAM_INT);
$query->execute();
$product_exists = $query->rowCount();
if ($product_exists == 0) {
$product_import = "INSERT INTO products ($fields, token, date_created) VALUES ($implode, :token, :date_created)";
$product_import = $db_website->prepare($product_import);
$product_import->execute(array(':token'=>$token, ':date_created'=>$todays_date_time));
$update_slug = "UPDATE products SET slug = LOWER(title),
slug = replace(slug, char(128), '')
WHERE token = :token";
$update_slug = $db_website->prepare($update_slug);
$update_slug->execute(array(':token'=>$token));
} else {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$stock_id = $row['stock_id'];
$product_import = "UPDATE products SET $this_is_the_variable_i_need_to_create_from_the_implode, token = :token, date_updated = :date_updated
WHERE stock_id = :stock_id";
$product_import = $db_website->prepare($product_import);
$product_import->execute(array(':stock_id'=>$stock_id, ':token'=>$token, ':date_updated'=>$todays_date_time));
}
$update_slug = "UPDATE products SET slug = LOWER(title),
slug = replace(slug, char(128), '')
WHERE token = :token";
$update_slug = $db_website->prepare($update_slug);
$update_slug->execute(array(':token'=>$token));
}
}
fclose($file);
}
My problems lies in that I want it to update existing products as well as create new ones.
In the code above I have begun by doing a query to check whether the stock id exists and if it doesn't insert the record with an else to say update if it does.
The part I am struggling on is how do I make it implode the COLUMN_NAME and the data that is sent in the csv file.
Any tip in the right direction would be greatly appreciated.
Thank you
Dan
If I'm understanding you correctly, you need to create a series of set clauses based on what's in the $data array (which is an array containing the values from a single line of your CSV). Excluding any kind of validation (either of the columns in your import file, or the data in your import file) you could do something like this:
$sets = array();
$update_values = array();
foreach( $data as $index => $val )
{
if(empty($have[ $index ]))
continue;
$field_name = $have[ $index ];
$update_values[] = $val;
$sets[] = "{$field_name} = ':val{$index}'";
}
if( $sets )
{
$update_values[] = $stock_id;
$set_clause = implode(',',$sets);
$product_import = $db_website->prepare("UPDATE products SET {$set_clause} WHERE stock_id = :stock_id");
$product_import->execute( $update_values );
}
Again, you're going to want validate your input, but this should give you the idea.
Thank you oliakaoil,
This is the code I used in the end for anybody else who may need it in the future
$sets = array();
$update_values = array();
foreach ($data as $index => $val) {
if (empty($have[$index]))
continue;
$field_name = $have[$index];
$update_values[] = $val;
$sets[] = "{$field_name} = '{$val}'";
}
if ($sets) {
$update_values[] = $stock_id;
$set_clause = implode(',',$sets);
$product_import = "UPDATE products SET {$set_clause}, token = :token
WHERE stock_id = :stock_id";
$product_import = $db_website->prepare($product_import);
$product_import->execute(array(':stock_id'=>$update_values[0], ':token'=>$token));
}
I have created a simple html table within PHP. Here is my code:
<div id="wrapper">
<div class="chart">
<h2>Files Uploaded to Knowledge Base</h2>
<table id="data-table" border="1" cellpadding="10" cellspacing="0">
<tr id=header>
<td>Users</td>
<td id=center>Project Files</td>
<td id=center>Process Files</td>
<td id=center>System Files</td>
<td id=center>Total Files</td>
</tr>
<?php
$di = new RecursiveDirectoryIterator('upload/project/');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
$pos = 15;
$file = substr("$filename", +$pos);
$lenght = strlen($file);
$pos = strpos($file, "/");
$file = substr("$file",0,$pos);
if($file1 != '.DS_Store'){
$serverfiles = mysql_query("SELECT uploader FROM Project WHERE location = '$file'");
while($row = mysql_fetch_array($serverfiles)) {
$occurance1 = $row['uploader'];
$array1[] = $occurance1;
}
}
}
$di = new RecursiveDirectoryIterator('upload/process/');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
$pos = 15;
$file = substr("$filename", +$pos);
$lenght = strlen($file);
$pos = strpos($file, "/");
$file = substr("$file",0,$pos);
if($file != '.DS_Store'){
$serverfiles = mysql_query("SELECT uploader FROM Process WHERE processlocation = '$file'");
while($row = mysql_fetch_array($serverfiles)) {
$occurance2 = $row['uploader'];
$array2[] = $occurance2;
}
}
}
$di = new RecursiveDirectoryIterator('upload/system/');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
$pos = 14;
$file = substr("$filename", +$pos);
$lenght = strlen($file);
$pos = strpos($file, "/");
$file = substr("$file",0,$pos);
if($file != '.DS_Store'){
$serverfiles = mysql_query("SELECT uploader FROM System WHERE location = '$file'");
while($row = mysql_fetch_array($serverfiles)) {
$occurance3 = $row['uploader'];
$array3[] = $occurance3;
}
}
}
$table_rows = array();
$counter = 0;
$uploader = mysql_query("Select username from members");
while($Load = mysql_fetch_array($uploader)){
$value = $Load['username'];
$tmp = array_count_values($array1);
$cnt = $tmp[$value];
$tmp2 = array_count_values($array2);
$cnt2 = $tmp2[$value];
$tmp3 = array_count_values($array3);
$cnt3 = $tmp3[$value];
$total = $cnt + $cnt2 + $cnt3;
//putting the values into array
$counter++;
$table_rows[$counter] = array();
$table_rows[$counter]['username'] = $value;
$table_rows[$counter]['project'] = $cnt;
$table_rows[$counter]['process'] = $cnt2;
$table_rows[$counter]['system'] = $cnt3;
$table_rows[$counter]['total'] = $total;
}
//function to sort the highest total value
function cmp_rows($a,$b) {
if ($a['total'] == $b['total']) {
return 0;
}
return ($a['total'] > $b['total']) ? -1 : 1;
}
usort($table_rows, 'cmp_rows');
//loop that prints values
foreach($table_rows as $row) {
echo "<tr>";
echo "<td>{$row['username']}</td>";
echo"<td id=center>{$row['project']}</td>";
echo"<td id=center>{$row['process']}</td>";
echo "<td id=center>{$row['system']}</td>";
echo "<td id=center>{$row['total']}</td>";
}
?>
</table>
</div>
</body></html>
The users are populated from a database table. The file figures are populated by reading and counting the amount of files in the directory. The table is sorted by highest first. I would also like to display values from the column 'accessDate' from the members table for each member but I'm not sure how to do this. It doesn't work like the other values above..
I do not know how to do this. Can someone please guide me in the right direction?
Thanks!
If you are just trying to get a formatted date into your table, something like this will do it (- see http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format for date formatting in MySQL)
...
//MySQL can format the date for you
$uploader = mysql_query(
"Select username, DATE_FORMAT(accessDate,'%m %d, %Y') formatted_date from members");
while($Load = mysql_fetch_array($uploader))
{
...
//putting the values into array
$counter++;
$table_rows[$counter] = array();
$table_rows[$counter]['date'] = $Load['formatted_date'];
$table_rows[$counter]['username'] = $value;
...
}
...
foreach($table_rows as $row)
{
echo "<tr>";
echo "<td>{$row['username']}</td>";
echo "<td>{$row['date']}</td>";
...
}
...