CodeIgniter Forums

Full Version: how to use model?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3

El Forum

[eluser]xwero[/eluser]
Code:
// the long version
$array = $this->model->compareBatch();
$kefiles = $array[0];
$qcfiles = $array[1];
$qccount = $array[2];
// short version
list($kefiles,$qcfiles,$qccount) = $this->model->compareBatch();
You don't have to name the variables in the controller the same as in the function.

El Forum

[eluser]syntaxerror[/eluser]
thanks i already starting to get it.
but why is it my loop is not looping it stuck to 0
Code:
for($x = 0; $x <= $file2_count; $x++)
                    {
                        $vtag1 = substr($keBatch[$x],178,1);
                        $vtag2 = substr($qcBatch[$x],178,1);
                        $page1 = substr($keBatch[$x],0,4);
                        $page2 = substr($qcBatch[$x],0,4);
                        $name1 = substr($keBatch[$x],7,78);
                        $name2 = substr($qcBatch[$x],7,78);
                        $addr1 = substr($keBatch[$x], 1, 78);
                        $addr2 = substr($qcBatch[$x], 1, 78);
                        $city1 = substr($keBatch[$x], 79, 30);
                        $city2 = substr($qcBatch[$x], 79, 30);
                        $state1 = substr($keBatch[$x], 110, 2);
                        $state2 = substr($qcBatch[$x], 110, 2);
                        $zc1 = substr($keBatch[$x], 112, 5);
                        $zc2 = substr($qcBatch[$x], 112, 5);
                        $tf1 = substr($keBatch[$x], 123, 40);
                        $tf2 = substr($qcBatch[$x], 123, 40);
                        $phone1  = substr($keBatch[$x], 164, 12);
                        $phone2  = substr($qcBatch[$x], 164, 12);
                            if($vtag2 == 1)
                                {
                                    return $x;
                                }else{
                                    return "vtag is not one";
                                }
                            
                    }

El Forum

[eluser]xwero[/eluser]
Because there is no content i guess

El Forum

[eluser]syntaxerror[/eluser]
i tried to return $file2_count and it returns 172.
i tried to return all variables and it returns result but it is not looping.
i also return $x, the value is 0
please kindly advice

thanks

El Forum

[eluser]xwero[/eluser]
What is the code you are using now

El Forum

[eluser]syntaxerror[/eluser]
Code:
function compareBatch()
    {
    
        $kebase = "//asecasianas2/DS_Keying/STATS/KE-DIR/";
        $qcbase = "//asecasianas2/DS_Keying/STATS/QC-DIR/";
        $dir = $this->input->post('directory');
        $ke = directory_map($kebase.$dir, TRUE);
        $qc = directory_map($qcbase.$dir, TRUE);
        $kelist = count($ke) - 1;
        $kelist2 = $kelist + 1;
        $qclist = count($qc) - 1;
        $qclist2 = $qclist+ 1;
        $count_comp = strcmp($kelist2, $qclist2);
        $row_comp = strcmp($kelist,$qclist);
            for($x = 0; $x <= $qclist; $x++)
            {

                $keName = ($kebase . $dir . "/" . $ke[$x]);
                $qcName = ($qcbase . $dir . "/" . $qc[$x]);
                $keBatch = file($keName);
                $qcBatch = file($qcName);
                $file2_count = count($qcBatch);
                $count = 1;
                for($x = 0; $x <= $file2_count; $x++)
                    {
                    
                        $vtag1 = substr($keBatch[$x],178,1);
                        $vtag2 = substr($qcBatch[$x],178,1);
                        $page1 = substr($keBatch[$x],0,4);
                        $page2 = substr($qcBatch[$x],0,4);
                        $name1 = substr($keBatch[$x],7,78);
                        $name2 = substr($qcBatch[$x],7,78);
                        $addr1 = substr($keBatch[$x], 1, 78);
                        $addr2 = substr($qcBatch[$x], 1, 78);
                        $city1 = substr($keBatch[$x], 79, 30);
                        $city2 = substr($qcBatch[$x], 79, 30);
                        $state1 = substr($keBatch[$x], 110, 2);
                        $state2 = substr($qcBatch[$x], 110, 2);
                        $zc1 = substr($keBatch[$x], 112, 5);
                        $zc2 = substr($qcBatch[$x], 112, 5);
                        $tf1 = substr($keBatch[$x], 123, 40);
                        $tf2 = substr($qcBatch[$x], 123, 40);
                        $phone1  = substr($keBatch[$x], 164, 12);
                        $phone2  = substr($qcBatch[$x], 164, 12);
                        return $x;
                            
                    }
                    
            }
        }

El Forum

[eluser]xwero[/eluser]
return breaks the loop. you have to look at return as the end of your function so it's similar to exit.

El Forum

[eluser]syntaxerror[/eluser]
i still have an error where ever i place my return,
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 172

Filename: models/process_model.php

Line Number: 35

El Forum

[eluser]xwero[/eluser]
That has nothing to do with the return i think. It has more to do with the array or string that is located on that line. If the number, 172, doesn't exist you get that error.

El Forum

[eluser]syntaxerror[/eluser]
i tried to make for statement manually
Code:
for($x = 0; $x <= 10; $x++)
{
return $x
}

but it return only 0, it didnt loop.
please advice
Pages: 1 2 3