Jump to content

chaturvedi

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

chaturvedi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hi, The following attached is the csv file i have to make. where 1,2,3..11 are the days of month and blank are the sundays. I could get the unique fields i.e. emp_id, emp_name, proj_name, proj_id , activity etc...in the format specified above but am having problem in gettin hours spent in each project daily throughout the month in horizontal row. i.e. corresponding to the project name. The following is my code: <? session_start(); include("SessionCheck.php"); include("Connection.php"); $stdt1=$_GET['sdate']; $enddt1=$_GET['edate']; $empid=$_GET['eid']; $s1="Select * from emp_master where emp_no='$empid'"; $r1=mysql_query($s1); $row=mysql_fetch_row($r1); $empnm=$row[1]; ?> <? $host = 'localhost'; $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = '"'; $csv_escaped = "\\"; // $result = mysql_query("Select distinct emp_no, emp_name, proj_id, proj_nm from tres having proj_nm=(Select wrkhrs from tres) where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $result = mysql_query("Select distinct emp_no, emp_name, proj_id, proj_nm from tres where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; //For the headings from SQL table for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while while($row = mysql_fetch_array()) $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $out; exit; ?> and the table in SQL consists of all the fields in vertical. Please consider the environment before you print / Merci de penser à l'environnement avant d'imprimer [attachment deleted by admin]
  2. ok here is the code that i have to generate a normal csv file... <? session_start(); include("SessionCheck.php"); include("Connection.php"); $stdt1=$_GET['sdate']; $enddt1=$_GET['edate']; $empid=$_GET['eid']; $s1="Select * from emp_master where emp_no='$empid'"; $r1=mysql_query($s1); $row=mysql_fetch_row($r1); $empnm=$row[1]; ?> <? $host = 'localhost'; $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = '"'; $csv_escaped = "\\"; //$result = mysql_query("Select distinct emp_no, emp_name, proj_id, proj_nm from tres having proj_nm=(Select wrkhrs from tres) where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $result = mysql_query("Select distinct emp_no, emp_name, proj_id, proj_nm from tres where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; //For the headings from SQL table for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $out; exit; now i want that if on day 3 4 and 7 i have worked in one project then the related hours should come corressponding to the project name. How do i get that?
  3. Hello, I have a PHP script that generates a simple csv file based on username entered. What i want to do is get the data into a horizontal line instead in column form based on the name of the project. There should be just one line per project name. please find the attachment for the same [attachment deleted by admin]
  4. what i actually want is that there is should be one line for a project with 30 cells for 30 days of months so that i can specify the workhours of the project...pls help its very urgent!!
  5. Hello, I want to generate a csv file with some data from mysql. I have been successful in generating the file the code for which i am including below. <? session_start(); include("SessionCheck.php"); include("Connection.php"); $stdt1=$_GET['sdate']; $enddt1=$_GET['edate']; $empid=$_GET['eid']; $s1="Select * from emp_master where emp_no='$empid'"; $r1=mysql_query($s1); $row=mysql_fetch_row($r1); $empnm=$row[1]; ?> <? $host = 'localhost'; $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = '"'; $csv_escaped = "\\"; $result = mysql_query("Select * from timeshiftentry_master where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $out; exit; /* $host = 'localhost'; $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = '"'; $csv_escaped = "\\"; $result = mysql_query("Select * from timeshiftentry_master where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $out; exit;*/ ?> and the table looks like following attachment[tres.jpg] but i want that there should be one line for each project. [attachment deleted by admin]
  6. Can u tell me how to use the Spreadsheet_excel_writer?
  7. Hello, What i want to do is get the data from mysql into the sheet i am attaching. I could make a simple csv file with relevant data. But i couldn't get the format as shown in the figure. Could someone please help me as this is very urgent and am not so good at PHP. I got a deadline to meet.. Please.. Thanks in advance.. There the following is my code for simple csv file... <? session_start(); include("SessionCheck.php"); include("Connection.php"); $stdt1=$_GET['sdate']; $enddt1=$_GET['edate']; $empid=$_GET['eid']; $s1="Select * from emp_master where emp_no='$empid'"; $r1=mysql_query($s1); $row=mysql_fetch_row($r1); $empnm=$row[1]; ?> <? $host = 'localhost'; $csv_terminated = "\n"; $csv_separator = ","; $csv_enclosed = '"'; $csv_escaped = "\\"; $result = mysql_query("Select * from timeshiftentry_master where emp_no='$empid' and dt>='$stdt1' and dt<='$enddt1'"); $fields_cnt = mysql_num_fields($result); $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { $l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, stripslashes(mysql_field_name($result, $i))) . $csv_enclosed; $schema_insert .= $l; $schema_insert .= $csv_separator; } // end for $out = trim(substr($schema_insert, 0, -1)); $out .= $csv_terminated; // Format the data while ($row = mysql_fetch_array($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if ($row[$j] == '0' || $row[$j] != '') { if ($csv_enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed; } } else { $schema_insert .= ''; } if ($j < $fields_cnt - 1) { $schema_insert .= $csv_separator; } } // end for $out .= $schema_insert; $out .= $csv_terminated; } // end while $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $out; exit; ?> Thanks but how do i include it in my code? am absolutely clueless...pls help.. [attachment deleted by admin]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.