KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Undefined index #2899

Open Augustine Arthur opened this topic on on Dec 11, 2022 - 4 comments

Augustine Arthur commented on Dec 11, 2022

This error message appears when I load the file. for the first time. However, when I click on the submit button the error disappears. Please any solution.

This is my view file:

<?php

use \koolreport\widgets\google\ColumnChart;
use \koolreport\widgets\koolphp\Table;
use \koolreport\inputs\Select2;

?> <div class="report-content"> <?php $years = $_POST["years"]; if (is_array($years)) $years = implode(", ", $years); $Mineral_Type = $_POST["Mineral_Type"]; $pdfTitle = $Mineral_Type. " in ".$years . " "; ?>

<div class="text-center">
    <h3>Mineral Production in Quantities and Value US$ for <?php echo $pdfTitle ?></h3>
    
</div>

<form method="post">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <b>Select Years</b>
                <?php 
                Select2::create(array(
                    "multiple"=>true,
                    "name"=>"years",
                    "dataSource"=>$this->src("data")->query("
                        select YEAR(Date_Produced) as 'Year'
                        from minerals_production
                        group by Year
                    "),
                    "attributes"=>array(
                        "class"=>"form-control"
                    )
                ));
                ?>
            </div>    

            <div class="form-group">
                <b>Select Minerals Type</b>
                <?php 
                Select2::create(array(
                    "multiple"=>false,
                    "name"=>"Mineral_Type",
                    "dataSource"=>$this->src("data")->query("
                        select Mineral_Type
                        from minerals_production
						Group by Mineral_Type")
                        /* oin orderdetails on orders.orderNumber = orderdetails.orderNumber
                        join products on products.productCode = orderdetails.productCode
                        ".(  $this->params["years"]!=array() ?"where YEAR(orderDate) in (:years)":"")."
                        group by productLine */
                    ->params(
                        $this->params["years"]!=array()?
                        array(":years"=>$this->params["years"]):
                        array()
                    ),
                    "attributes"=>array(
                        "class"=>"form-control"
                    )
                ));
                ?>                
            </div>
			<div class="form-group">
                <button class="btn btn-primary">Submit</button>
				<button formaction="exportMyReportQuan.php" class="btn btn-primary">Download PDF</button>
				
			
            </div>    
            </div>    
        </div>
    </div>
    
</form>
<?php

/* Table::create(array(

    "dataSource"=>$this->dataStore("orders"),
    "columns"=>array(
	 "Year"=>array(
	 "type"=>"date",
               "label"=>"Year"
			   ),
	  "Mineral_Type"=>array(
               "label"=>"Minerals"
			   ),
	"Qty_Produced"=>array(
                "type"=>"number",
                "label"=>"Quantity",
               // "prefix"=>"$",
                "emphasis"=>true
            ),
			 "Qty_Produced"=>array(
                "type"=>"number",
                "label"=>"Quantity",
               // "prefix"=>"$",
                "emphasis"=>true
            ),
			"Min_Value"=>array(
                "type"=>"number",
                "label"=>"Value US$",
                //"prefix"=>"$",
                "emphasis"=>true
            )
			),
    "grouping"=>array(
      // "Year",
       // "Mineral_Type"
    ),
    "paging"=>array(
        "pageSize"=>25
    ),
    "cssClass"=>array(
        "table"=>"table-bordered"
    )
)); */
?>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>


<i class="fa fa-arrow-down" style="font-size:24px;"></i>

<div style="margin-top:20px;">
<?php
Table::create(array(
    "dataSource"=>$this->dataStore("result"),
	 "columns"=>array(
	 "Year"=>array(
	 "type"=>"date",
     "label"=>"Year"
			   ),
	  "Mineral_Type"=>array(
               "label"=>"Minerals"
			   ),
	"Qty_Produced"=>array(
                "type"=>"number",
                "label"=>"Quantity",
               // "prefix"=>"$",
                "emphasis"=>true
            ),
			 "Qty_Produced"=>array(
                "type"=>"number",
                "label"=>"Quantity",
               // "prefix"=>"$",
                "emphasis"=>true
            ),
			"Min_Value"=>array(
                "type"=>"number",
                "label"=>"Value US$",
                //"prefix"=>"$",
                "emphasis"=>true
            )
			),
	
    "cssClass"=>array(
        "table"=>"table-bordered table-striped table-hover"
    )
	
));
?>
</div>
 
<?php
ColumnChart::create(array(

"title"=>"Minerals Produced By Quantity and Value in US$",
        "dataStore"=>$this->dataStore('result'),
        "width"=>"100%",
        "height"=>"500px",
        "columns"=>array(
           /*  "Mineral_Type"=>array(
               "label"=>"Minerals"
			   ), */
		 "Year"=>array(
	     "type"=>"date",
         "label"=>"Year"
			   ),
			   
        
    "Qty_Produced"=>array(
                "type"=>"number",
                "label"=>"Quantity",
               // "prefix"=>"$",
                "emphasis"=>true
            ),
			"Min_Value"=>array(
                "type"=>"number",
                "label"=>"Value US$",
                //"prefix"=>"$",
                "emphasis"=>true
            ),
			

        )
       // "options"=>array(
       //     "title"=>"Minerals Produced By Quantity",
       // )
    ));
?>

</div>

Sebastian Morales commented on Dec 12, 2022

Pls replace this line in your report view:

    $years = $_POST["years"]; 

with this one:

    $years = $this->params["years"]; 

There should be default value for "years" in your report class' function defaultParamValues() as well as "years" returned in function bindParamsToInputs().

Do the same for $Mineral_Type = $_POST["Mineral_Type"];

Augustine Arthur commented on Dec 12, 2022

The undefined index errors have been corrected. However, I am still confronted with this error: Notice: Array to string conversion in C:\xampp\htdocs\koolreport\koolreport\mc\MyReportQuanValue.view.php on line 13 This is the view file:

<?php
	use \koolreport\widgets\google\ColumnChart;
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\inputs\Select2;
?>
<div class="report-content">
<?php
$years = $this->params["years"];
//$years = $_POST["years"];
if (is_array($years)) $years = implode(", ", $years);

$Mineral_Type = $this->params["Mineral_Type"];
$pdfTitle = $Mineral_Type. " in ".$years ."";
?>
    <div class="text-center">
        <h3>Mineral Production in Quantities and Value US$ for <?php echo $pdfTitle ?></h3>
        
    </div>
    
    <form method="post">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <b>Select Years</b>
                    <?php 
                    Select2::create(array(
                        "multiple"=>true,
                        "name"=>"years",
                        "dataSource"=>$this->src("data")->query("
                            select YEAR(Date_Produced) as 'Year'
                            from minerals_production
                            group by Year
                        "),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>
                </div>    
  
                <div class="form-group">
                    <b>Select Minerals Type</b>
                    <?php 
                    Select2::create(array(
                        "multiple"=>false,
                        "name"=>"Mineral_Type",
                        "dataSource"=>$this->src("data")->query("
                            select Mineral_Type
                            from minerals_production
							Group by Mineral_Type")
                            /* oin orderdetails on orders.orderNumber = orderdetails.orderNumber
                            join products on products.productCode = orderdetails.productCode
                            ".(  $this->params["years"]!=array() ?"where YEAR(orderDate) in (:years)":"")."
                            group by productLine */
                        ->params(
                            $this->params["years"]!=array()?
                            array(":years"=>$this->params["years"]):
                            array()
                        ),
                        "attributes"=>array(
                            "class"=>"form-control"
                        )
                    ));
                    ?>                
                </div>
				<div class="form-group">
                    <button class="btn btn-primary">Submit</button>
					<button formaction="exportMyReportQuan.php" class="btn btn-primary">Download PDF</button>
					
				
                </div>    
                </div>    
            </div>
        </div>
        
    </form>
    <?php
   /*  Table::create(array(
        "dataSource"=>$this->dataStore("orders"),
        "columns"=>array(
		 "Year"=>array(
		 "type"=>"date",
                   "label"=>"Year"
				   ),
		  "Mineral_Type"=>array(
                   "label"=>"Minerals"
				   ),
		"Qty_Produced"=>array(
                    "type"=>"number",
                    "label"=>"Quantity",
                   // "prefix"=>"$",
                    "emphasis"=>true
                ),
				 "Qty_Produced"=>array(
                    "type"=>"number",
                    "label"=>"Quantity",
                   // "prefix"=>"$",
                    "emphasis"=>true
                ),
				"Min_Value"=>array(
                    "type"=>"number",
                    "label"=>"Value US$",
                    //"prefix"=>"$",
                    "emphasis"=>true
                )
				),
        "grouping"=>array(
          // "Year",
           // "Mineral_Type"
        ),
        "paging"=>array(
            "pageSize"=>25
        ),
        "cssClass"=>array(
            "table"=>"table-bordered"
        )
    )); */
    ?>
	<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>

</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result"),
		 "columns"=>array(
		 "Year"=>array(
		 "type"=>"date",
         "label"=>"Year"
				   ),
		  "Mineral_Type"=>array(
                   "label"=>"Minerals"
				   ),
		"Qty_Produced"=>array(
                    "type"=>"number",
                    "label"=>"Quantity",
                   // "prefix"=>"$",
                    "emphasis"=>true
                ),
				 "Qty_Produced"=>array(
                    "type"=>"number",
                    "label"=>"Quantity",
                   // "prefix"=>"$",
                    "emphasis"=>true
                ),
				"Min_Value"=>array(
                    "type"=>"number",
                    "label"=>"Value US$",
                    //"prefix"=>"$",
                    "emphasis"=>true
                )
				),
		
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
		
    ));
    ?>
    </div>
	 
	<?php
    ColumnChart::create(array(
	
	"title"=>"Minerals Produced By Quantity and Value in US$",
            "dataStore"=>$this->dataStore('result'),
            "width"=>"100%",
            "height"=>"500px",
            "columns"=>array(
               /*  "Mineral_Type"=>array(
                   "label"=>"Minerals"
				   ), */
			 "Year"=>array(
		     "type"=>"date",
             "label"=>"Year"
				   ),
				   
            
        "Qty_Produced"=>array(
                    "type"=>"number",
                    "label"=>"Quantity",
                   // "prefix"=>"$",
                    "emphasis"=>true
                ),
				"Min_Value"=>array(
                    "type"=>"number",
                    "label"=>"Value US$",
                    //"prefix"=>"$",
                    "emphasis"=>true
                ),
				

            ),
          // "options"=>array(
		   // "hAxis" => array(
                "title" => "Total Sales",
           //     "title"=>"Minerals Produced By Quantity",
           // )
        ));
    ?>

</div>
Sebastian Morales commented on Dec 13, 2022

Pls check your param value and type with this command in your report view:

$Mineral_Type = $this->params["Mineral_Type"];
echo "Mineral_Type = "; var_dump($Mineral_Type); echo "<br>";

If it's of type Array pls check function defaultParamValues() in your report class so that the initial value of "Mineral_Type" is not an array.

Augustine Arthur commented on Dec 13, 2022

Thank you so much. I only changed "Mineral_Type"=>array(" "), to "Mineral_Type"=>" ", *Note The select2::create(array(

                    "multiple"=>false,
                    "name"=>"Mineral_Type",

Because I had set the multiple to false I also had to remove the array as shown above. * protected function defaultParamValues()

{
    return array(
        "years"=>array(2017),
        "Mineral_Type"=>" ",
     
    );
}

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None