readfile and insert to db help

#11
[eluser]sasori[/eluser]
sir, i tried both the orig. $a[$i][0] and $a[$i][1]

then i tried to
Code:
$data = array(
                        'compcode' => $a[$i][0],
                        'pricepercent' => $a[$i][1],
                        'compname' => $a[$i][2],
                        'volume' => $a[$i][3]);

          #$this->db->insert('stocks',$data);
          echo "<pre>",print_r($data),"</pre>";

Quote:Array
(
[compcode] => ABA
[pricepercent] => 0.97 0.00%
[compname] => Abacus A
[volume] => 50,000
)
1

Array
(
[compcode] => ABS
[pricepercent] => 22.00 1.1494%
[compname] => ABS-CBN
[volume] => 60,700
)
1

Array
(
[compcode] => ABSP
[pricepercent] => 22.25 1.1364%
[compname] => ABS-CBN PDR
[volume] => 78,500
)
1

it seem to work fine..but then when i scrolled down the browser i saw these 3 stuffs
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 1

Filename: models/stock_model.php

Line Number: 29
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 2

Filename: models/stock_model.php

Line Number: 34
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 3

Filename: models/stock_model.php

Line Number: 35

i got no idea why it got 3 errors at the last part ?

#12
[eluser]flaky[/eluser]
do a
Code:
print_r($a);
so we can see what values does $a hold;

#13
[eluser]sasori[/eluser]
ok sir i did
Code:
echo "<pre>",print_r($a),"</pre>";
this time the error lowered down to "2" and this time in the last array,
awhile ago the batch of error was on the 4th last

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 2

Filename: models/stock_model.php

Line Number: 34
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 3

Filename: models/stock_model.php

Line Number: 35

#14
[eluser]flaky[/eluser]
try this

Code:
&lt;?php

class Stock_model extends Model{

    public function __construct(){
        parent::__construct();
    }
    
    function putData($txt)
    {
        $handle = file_get_contents($txt);
        $var_array = explode(";",$handle);
        $a = array_chunk($var_array,4);
        
            for($i=0;$i<sizeof($a);$i++)
            {
                if(isset($a[$i][1]))
                    $a[$i][1] = preg_replace("/\s\%/","%",$a[$i][1]);
                
                if(isset($a[$i][0]))
                    $data['compcode'] = $a[$i][0];
                
                if(isset($a[$i][1]))
                    $data['pricepercent'] = $a[$i][1];
                    
                if(isset($a[$i][2]))
                    $data['compname'] = $a[$i][2];
                    
                if(isset($a[$i][3]))
                    $data['volume'] = $a[$i][3];
                
                //print_r($data);
                //$this->db->insert('stocks',$data);
            }

        return $this->db->affected_rows();
    }

}

#15
[eluser]sasori[/eluser]
thank you sir. case solved


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.