novice for variables questions - El Forum - 10-10-2008
[eluser]syntaxerror[/eluser]
hi,
can anyone please help me with these simple question, i think.
i have codes in php
Code: $vtag1 = substr($file1[$x],178,1);
$vtag2 = substr($file2[$x],178,1);
$page1 = substr($file1[$x],0,4);
$page2 = substr($file2[$x],0,4);
$name1 = substr($file1[$x],7,78);
$name2 = substr($file2[$x],7,78);
$addr1 = substr($file1[$x], 1, 78);
$addr2 = substr($file2[$x], 1, 78);
$city1 = substr($file1[$x], 79, 30);
$city2 = substr($file2[$x], 79, 30);
$state1 = substr($file1[$x], 110, 2);
$state2 = substr($file2[$x], 110, 2);
$zc1 = substr($file1[$x], 112, 5);
$zc2 = substr($file2[$x], 112, 5);
$tf1 = substr($file1[$x], 123, 40);
$tf2 = substr($file2[$x], 123, 40);
$phone1 = substr($file1[$x], 164, 12);
$phone2 = substr($file2[$x], 164, 12);
but code igniter doesnt accepts variables like this in controller.
so i have to make $data[....] all variables.
Code: $data['vtag1'] = substr($data['file1'][$x],178,1);
$data['vtag2'] = substr($data['file2'][$x],178,1);
$data['name1'] = substr($data['file1'][$x],7,78);
$data['name2'] = substr($data['file2'][$x],7,78);
is there shortcut in making variables in controller of codeigniter?
and also how to use for loop in controller?
thanks
novice for variables questions - El Forum - 10-10-2008
[eluser]Yash[/eluser]
what is $file1[$x]
try like this
Code: $data['vtag1'] = substr($file1[$x],178,1);
$data['vtag2'] = substr($file[$x],178,1);
$data['name1'] = substr($file1[$x],7,78);
$data['name2'] = substr($file2[$x],7,78);
don't use data for these values
novice for variables questions - El Forum - 10-10-2008
[eluser]syntaxerror[/eluser]
thanks,
but there is an error
Code: Severity: Notice
Message: Undefined variable: file1
Filename: controllers/front_cont.php
Line Number: 44
BTW my whole function is this
Code: function process()
{
$data['title'] = "DS Validator";
$data['header'] = "DS Validator";
$data['kebase'] = "//asecasianas2/DS_Keying/STATS/KE-DIR/";
$data['qcbase'] = "//asecasianas2/DS_Keying/STATS/QC-DIR/";
$data['ke']= directory_map($data['kebase'].$_POST["directory"], TRUE);
$data['qc']= directory_map($data['qcbase'].$_POST["directory"], TRUE);
$data['kelist'] = count($data['ke']) - 1;
$data['kelist2'] = $data['kelist']+ 1;
$data['qclist'] = count($data['qc']) - 1;
$data['qclist2'] = $data['qclist']+ 1;
$data['count_comp'] = strcmp($data['kelist2'], $data['qclist2']);
$data['row_comp'] = strcmp($data['kelist'],$data['qclist']);
for($x = 0; $x <= $data['qclist']; $x++)
{
$data['ke_batch'] = $data['ke'][$x];
$data['qc_batch'] = $data['qc'][$x];
$data['file1'] = file($data['kebase'].$_POST["directory"]."/".$data['ke_batch']);
$data['file2'] = file($data['qcbase'].$_POST["directory"]."/".$data['qc_batch']);
$data['file2_count'] = count($data['file2']);
$data['count'] = 1;
for($x = 0; $x <= $data['file2_count']; $x++)
{
$data['vtag1'] = substr($file1[$x],178,1);
$data['vtag2'] = substr($file2[$x],178,1);
$data['name1'] = substr($file1[$x],7,78);
$data['name2'] = substr($file2[$x],7,78);
if($data['vtag1'] == 1)
{
$data['str'] = $data['vtag1'];
}else{
$data['str']= 'level2';
}
$data['count']++;
}
$this->load->view('process', $data);
}
novice for variables questions - El Forum - 10-10-2008
[eluser]Yash[/eluser]
what is $file1[$x]
novice for variables questions - El Forum - 10-10-2008
[eluser]syntaxerror[/eluser]
$file1[$x] is an array of a file.
i want to read a file and make it an array.
novice for variables questions - El Forum - 10-10-2008
[eluser]Yash[/eluser]
lemme know any error...
Code: function process()
{
$data['title'] = "DS Validator";
$data['header'] = "DS Validator";
$kebase = "//asecasianas2/DS_Keying/STATS/KE-DIR/";
$qcbase = "//asecasianas2/DS_Keying/STATS/QC-DIR/";
$ke= directory_map($kebase.$_POST["directory"], TRUE);
$qc= directory_map($qcbase.$_POST["directory"], TRUE);
$kelist = count($ke) - 1;
$kelist2 = $kelist+ 1;
$qclist = count($qc) - 1;
$qclist2 = $qclist+ 1;
$data['count_comp'] = strcmp($kelist2, $qclist2);
$data['row_comp'] = strcmp($kelist,$qclist);
for($x = 0; $x <= $qclist; $x++)
{
$ke_batch = $ke[$x];
$qc_batch = qc[$x];
$file1 = file($kebase.$_POST["directory"]."/".$ke_batch);
$file2 = file($qcbase.$_POST["directory"]."/".$qc_batch]);
$file2_count = count($file2);
$count = 1;
for($x = 0; $x <= $file2_count; $x++)
{
$vtag1 = substr($file1[$x],178,1);
$data['vtag2'] = substr($file2[$x],178,1);
$data['name1'] = substr($file1[$x],7,78);
$data['name2'] = substr($file2[$x],7,78);
if($vtag1 == 1)
{
$data['str'] = $vtag1;
}else{
$data['str']= 'level2';
}
$count++;
}
$this->load->view('process', $data);
}
novice for variables questions - El Forum - 10-10-2008
[eluser]syntaxerror[/eluser]
error
Code: Severity: Notice
Message: Undefined index: count
Filename: controllers/front_cont.php
Line Number: 56
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 172
Filename: controllers/front_cont.php
Line Number: 47
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 172
Filename: controllers/front_cont.php
Line Number: 49
novice for variables questions - El Forum - 10-10-2008
[eluser]Yash[/eluser]
already modify that..try now
$count++; // forget to remove $data part
dude use ur brain ....
novice for variables questions - El Forum - 10-10-2008
[eluser]syntaxerror[/eluser]
i know php but im new and not familiar in using codeigniter
my working code is this
Code: <pre>
<?php
$file1 = file('//asecasianas2/DS_Keying/STATS/KE-DIR/SC41001A/COT029.DTA');
$file2 = file('//asecasianas2/DS_Keying/STATS/QC-DIR/SC41001A/COT029.DTA');
$file1_count = count($file1);
$file2_count = count($file2);
$count = 1;
for($x = 0; $x <= $file2_count; $x++)
{
$vtag1 = substr($file1[$x],178,1);
$vtag2 = substr($file2[$x],178,1);
$page1 = substr($file1[$x],0,4);
$page2 = substr($file2[$x],0,4);
$name1 = substr($file1[$x],7,78);
$name2 = substr($file2[$x],7,78);
$addr1 = substr($file1[$x], 1, 78);
$addr2 = substr($file2[$x], 1, 78);
$city1 = substr($file1[$x], 79, 30);
$city2 = substr($file2[$x], 79, 30);
$state1 = substr($file1[$x], 110, 2);
$state2 = substr($file2[$x], 110, 2);
$zc1 = substr($file1[$x], 112, 5);
$zc2 = substr($file2[$x], 112, 5);
$tf1 = substr($file1[$x], 123, 40);
$tf2 = substr($file2[$x], 123, 40);
$phone1 = substr($file1[$x], 164, 12);
$phone2 = substr($file2[$x], 164, 12);
if($vtag2 == 1)
{
$name_comp = strcmp($name1, $name2);
if($name_comp != 0)
{
//echo "line".$count."error name" . "<br>";
$err_stat = 1;
$err_line = $count;
$err_name1 = $name1;
$err_name2 = $name2;
echo "Line" . $err_line . " " . "KE Name" . " " . $err_name1 . "<br> ";
echo " QC Name" . " " . $err_name2 . "<br>";
}
}else{
$addr_comp = strcmp($addr1, $addr2);
$city_comp = strcmp($city1, $city2);
$state_comp = strcmp($state1, $state2);
$zc_comp = strcmp($zc1, $zc2);
$tf_comp = strcmp($tf1, $tf2);
$phone_comp = strcmp($phone1, $phone2);
if($addr_comp != 0)
{
$err_line = $count;
$err_addr1 = $addr1;
$err_addr2 = $addr2;
echo "Line" . $err_line . " " . "KE address" . " " . $err_addr1 . "<br>";
echo " QC address" . " " . $err_addr2 . "<br>";
}
if($city_comp != 0)
{
$err_line = $count;
$err_city1 = $city1;
$err_city2 = $city2;
echo "Line" . $err_line . " " . "KE City" . " " . $err_city1 . "<br>";
echo " QC City" . " " . $err_city2 . "<br>";
}
if($state_comp != 0)
{
$err_line = $count;
$err_state1 = $state1;
$err_state2 = $state2;
echo "Line" . $err_line . " " . "KE State" . " " . $err_state1 . "<br>";
echo " QC State" . " " . $err_state2 . "<br>";
}
if($zc_comp != 0)
{
$err_line = $count;
$err_zc1 = $zc1;
$err_zc2 = $zc2;
echo "Line" . $err_line . " " . "KE ZipCode" . " " . $err_zc1 . "<br>";
echo " QC ZipCode" . " " . $err_zc2 . "<br>";
}
if($tf_comp != 0)
{
$err_line = $count;
$err_tf1 = $tf1;
$err_tf2 = $tf2;
echo "Line" . $err_line . " " . "KE Toll Free Text" . " " . $err_tf1 . "<br>";
echo " QC Toll Free Text" . " " . $err_tf2 . "<br>";
}
if($phone_comp != 0)
{
$err_line = $count;
$err_phone1 = $phone1;
$err_phone2 = $phone2;
echo "Line" . $err_line . " " . "KE phone" . " " . $err_phone1 . "<br>";
echo " QC phone" . " " . $err_phone2 . "<br>";
}
}
$count++;
}
?>
</pre>
but im having a hard time in transferring it in codeigniter
novice for variables questions - El Forum - 10-10-2008
[eluser]Colin Williams[/eluser]
For one, this should be in a model, not the controller. Controllers aren't meant to retrieve and parse files. And it looks like you're scraping a file, so the process is just inherently going to be messy and tedious (messy + tedious != controller). Once you figure out how to get it into the array structure you want, you can then have the model return this array to the controller. The controller could be responsible for passing instructions to the model function that does this (like the paths of file1 and file2, for instance)
|