Hi while exporting Dynmaic row and Column only columns exported not row, giving a Cannot modify header information - headers already sent by (output started at /var/www/html/excel/excelv1.php:615) in /var/www/html/excel/excelv1.php on line 625 error to find out
Error - image
Here is my code
For Dynamic Column code its working fine
$out_table = '';
$k = 0;
mysql_data_seek($query_result1, 0);
$col = 36;
while ($row1 = mysql_fetch_array($query_result1, MYSQL_ASSOC)) {
$sheet->setCellValueByColumnAndRow($col, 1, trim($labels[$k] . " (value1)", ','));
$sheet->setCellValueByColumnAndRow($col + 1, 1, trim($labels[$k] . " (value2)", ','));
$col = $col + 2;
$k++;
}
echo $out_table;
Here is Dynamic Row Code Which is not Working
$inn_table = "";
if($result['qualification']['dd1']!="") {
$dd1 = explode(",",$result['qualification']['dd1']);
}
if($result['qualification']['dd2']!=""){
$dd2 = explode(",",$result['qualification']['dd2']);
}
for($i=0;$i<count($labels);$i++) {
if($result['qualification']['dd1']!="") {
$found=false;
for($j=0;$j<count($dd1);$j++) {
$temp = explode(">",$dd1[$j]);
if($temp[0]==$labels[$i]) {
$name = explode(">",$dd1[$j]);
$inn_table .= '<td>'.$name[1].'</td>';
$found=true;
break;
}
}
}
While printing column and row from an array it's showing blank not exporting any data
$inn_table = "";
if ($result['qualification']['dd1'] != "") {
$dd1 = explode(",", $result['qualification']['dd1']);
}
if ($result['qualification']['dd2'] != "") {
$dd2 = explode(",", $result['qualification']['dd2']);
}
for ($i = 0; $i < count($labels); $i++) {
if ($result['qualification']['dd1'] != "") {
echo '<pre>First';
print_r($dd1); ** //echo arrays**
for ($j = 0; $j < count($dd1); $j++) {
$temp = explode(">", $dd1[$j]);
if ($temp[0] == $labels[$i]) {
$name = explode(">", $dd1[$j]);
echo '<pre>First ';
print_r($name[1]); ** //echo names**
}
}
}
}
Here is my Array structure
and Here names which i am trying to export from Array
So i only trying to export names from that array please help
foreach($labels as $ind => $label) {
$index = $ind + 2;
$letter = range('A', 'Z')[$ind2];
$val = explode('>', $data);
$objPHPExcel->getActiveSheet()->setCellValue($letter . $index, $val[1]);
}
I have a data set that I'm searching for certain IPA symbols. I'd like to restrict the search domain in accordance with the value of $where shown in the code below, but don't know how. EDIT: Where $where is "onset" "nucleui" and "coda." Does anyone know how to restrict the search domain? (The code below is in php but the file is linked to an HTML file that a person could use to search for the IPA symbols in the data set.) EDIT: See added code at bottom.
//set up variables
$words = $table[0]; //row 1 of table
$target = $table[1]; //row 2
$indices = array(); //used to store column numbers
$IPAstr = $_POST["ipa"];
$where = $_POST["where"];
//Find $IPAstr in $target
for($i=1; $i<count($target); $i++)
{
if (mb_strpos($target[$i],$IPAstr) !== false)
$indices[] = $i;
}
//List realizations & count frequency
for($i=0; $i<count($indices); $i++)
{
$index = $indices[$i];
$ipalist = array();
echo "<table border=1><tr><td>".$target[$index]." in " . $words[$index]."</td></tr><td>";
//output each speaker and count frequency
for ($j=2; $j<count($table); $j++) {
echo ($j-1).": ".$table[$j][$index]."<br>";
$ipalist[$table[$j][$index]]++;
}
echo "<br>";
//output frequency list
foreach($ipalist as $ipa=>$fre)
echo "$ipa: $fre<br>";
echo "</td></tr></table>";
}
//Code to help search for "onset" "nuclei" and "coda"
//list onsets only
echo "Onsets only<br>";
for($col=0; $col<count($table[0]); $col++) {
$s = $table[0][$col];
if (whichSyllPart($s) == 'o') echo "$s ";
}
//list nuclei only
echo "Nuclei only<br>";
for($col=0; $col<count($table[0]); $col++) {
$s = $table[0][$col];
if (whichSyllPart($s) == 'n') echo "$s ";
}
//list codas only
echo "Codas only<br>";
for($col=0; $col<count($table[0]); $col++) {
$s = $table[0][$col];
if (whichSyllPart($s) == 'c') echo "$s ";
}
In order to restrict the search domain you need to enter the following code as part of the "//Find $IPAstr in $target" section of the code.
//Find $IPAstr in $target
for($i=1; $i<count($target); $i++)
{
if ($where == whichSyllPart($words[$i])){
if (mb_strpos($target[$i],$IPAstr) !== false)
$indices[] = $i;
}
else if ($where == "everywhere"){
if (mb_strpos($target[$i],$IPAstr) !== false)
$indices[] = $i;
}
}
For this to run you need a function whichSyllPart()
function whichSyllPart($sy)
{
$pt = $sy[strlen($sy)-1];
return($pt);
}
This adds an if/else if statement including the whichSyllPart() function that restricts the search according to the value of $where.
I'm looping in an array, filling it with data from a file.
I'm trying to change the data from one cell to another and then leave the old cell empty.
So far I was using this code and it worked:
$custom_array_price['b'] = $custom_array_price['c'];
unset($custom_array_price['c']);
But for this specific case it doesn't work. It deletes the data before it gets copied.
How do I make it work?
This is the code I'm trying to use now:
$custom_array_price['c'] = $custom_array_price['d'];
unset($custom_array_price['d']);
The loop looks like this:
foreach ( $custom_array_price as $custom_key => $custom_value ) {
$custom_value = utf8_encode($custom_value);
if ( $custom_key == 'a' ){
if ( $custom_value == "Fecha:" ){
if( count($recibos) > 0 ){
$recibos[$cont]['html'].= "</tr>";
$recibos[$cont]['html'].= "</table>";
$cont++;
$times = 0;
}
$recibos[$cont]['html'] = "<table>";
$recibos[$cont]['html'].= "<tr>";
}else{
$recibos[$cont]['html'].= "<tr>";
}
}
if ( $times <= 5 ){
$custom_array_price['b'] = $custom_array_price['c'];
$custom_array_price['c'] = $custom_array_price['d'];
unset($custom_array_price['d']);
}
if ( $custom_value == "Neto a Pagar:"){
$custom_array_price['l'] = $custom_array_price['k'];
unset($custom_array_price['k']);
}
if ( $custom_value == "A001"){
$custom_array_price['g'] = $custom_array_price['i'];
unset($custom_array_price['i']);
}
$recibos[$cont]['html'].= "<td>";
$recibos[$cont]['html'].= $custom_value;
$recibos[$cont]['html'].= "</td>";
}
$recibos[$cont]['html'].= "</tr>";
Another part of the code. Where the csv file is being read and the data is being copied:
$recibos = array();
foreach($data_rows_price as $key => $value){
$times++;
for($i = 0; $i < count($value); $i++){
if(array_key_exists('mapping'.$i,$ret_array)){
if($ret_array['mapping'.$i]!='add_custom'.$i){
$new_post[$ret_array['mapping'.$i]] = $value[$i];
}
else{
$new_post[$ret_array['textbox'.$i]] = $value[$i];
$custom_array_price[$ret_array['textbox'.$i]] = $value[$i];
}
}
}
for($inc = 0; $inc < count($value); $inc++){
foreach($keys_price as $k => $v){
if(array_key_exists($v,$new_post)){
$custom_array_price[$v] = $new_post[$v];
}
}
}
This code works perfectly except that it doesn't print the last 2 rows of my csv file:
This is the file:
603629,0,ATLV0008,"Vendor1",1942.60,11/04/2010,1942.60,9/1-9/30/10,EFT-JP
603627,2,ATLV0008,"Vendor1",1242.40,11/04/2010,1242.40,7/1-7/31/10,EFT-JP
600023,0,FLD4V0003,"Vendor2",1950.00,06/15/2010,1950.00,6/14/10 Request,EFT-JP
600024,0,FLD4V0003,"Vendor2",1800.00,06/15/2010,1800.00,6/14/10 Request,EFT-JP
603631,0,ATLV5066,"Vendor2",1000.00,11/09/2010,1000.00,11/4/10 Check Request,PM2
603647,0,ATLV5027,"DVendor3",2799.80,11/15/2010,2799.80,10/1-10/31/10 Bishop,PM2
603642,5,ATLV5027,"Vendor3",482.40,11/15/2010,482.40,10/1-10/18/10 Allen,PM2
603653,0,ATLV0403,"Vendor4",931.21,11/17/2010,931.21,9/1-9/30/10,EFT-JP
603661,0,ATLV0105,"Vendor5",26.75,11/19/2010,26.75,093139,PM2
603660,1,ATLV0105,"Vendor5",5.35,11/19/2010,5.35,093472,PM2
Here is the code: (It needs to display the sum of 2 rows with the same vendor before the actual rows)
if (($handle = fopen('upload/ATLANTA.csv', "r")) !== FALSE) {
while (($row_array = fgetcsv($handle, 1000, ","))) {
foreach ($row_array as $key => $val) {
$row_array[$key] = trim(str_replace('"', '', $val));
ob_flush();
}
$complete[] = $row_array;
ob_flush();
}
}
flush();
$prevVendor = '';
$sum = 0;
$venData = '';
if (isset($complete)) {
foreach ($complete as $key => $val) {
$venData .= "<br/>";
$currVendor = $complete[$key][3];
if ($currVendor != $prevVendor){
if ($prevVendor != NULL){
print "<br/>";
print $sum . "<br/>";
print $venData;
$sum = 0; $venData = '';
}
}
foreach ($val as $ikey => $ival){
if ($ikey != 1){
$venData .= $ival . ' ';
$prevVendor = $val[3];
}
}
if ($currVendor == $prevVendor){
$sum += $complete[$key][6];
}
}
}
I don't really understand your problem but if you want to get (and save it wherever you want) the sum of each vendors, you should do something like this :
$prevVendor = null;
$venData = '';
$sums = array();
if (isset($complete) && is_array($complete)) {
$lim = count($complete);
for ($key=0;$key<$lim;++$key) { // no need foreach for simple array
$venData .= "<br/>";
$currVendor = $complete[$key][3];
if ($currVendor != $prevVendor){
if ($prevVendor != null){
print "<br/>";
print $venData;
}
$venData = '';
$prevVendor = $currVendor;
$sums[$currVendor] = 0; // set the counter to 0
}
foreach ($complete[$key] as $ikey => $ival){
if ($ikey != 1){
$venData .= $ival . ' '; // is useful for you I guess
}
}
$sums[$currVendor] += $complete[$key][6]; // add amounts
}
}
if ($prevVendor != null){ // you need to do this to display the last record
print "<br/>";
print $venData;
}
var_export($sums); // check results
This can be some syntax errors ...