Jump to content

sasori

Members
  • Posts

    332
  • Joined

  • Last visited

Everything posted by sasori

  1. function putData($txt) { $handle = read_file($txt); $var_array_parent = explode("\n", $handle); foreach($var_array_parent as $value) { $var_array = explode(";", $value); $a = array_chunk($var_array, 4); } echo "<pre>",print_r($a),"</pre>"; foreach($a as $k=>$v) { $temp = explode(' ',$v[1]); unset($a[$k][1]); $a[$k][] = $temp[0]; $a[$k][] = $temp[1].$temp[2]; } the result was Array ( [0] => Array ( [0] => ABA [1] => 0.97 0.00 % [2] => Abacus A [3] => 50,000 ) [1] => Array ( [0] => ABS [1] => 22.00 1.1494 % [2] => ABS-CBN [3] => 60,700 ) and ofcourse there are these errors at the end of it A PHP Error was encountered Severity: Notice Message: Undefined offset: 1 Filename: models/stock_model.php Line Number: 54 A PHP Error was encountered Severity: Notice Message: Undefined offset: 1 Filename: models/stock_model.php Line Number: 57 A PHP Error was encountered Severity: Notice Message: Undefined offset: 2 Filename: models/stock_model.php Line Number: 57 Fatal error: Cannot use string offset as an array in C:\xampp\htdocs\myapp\system\application\models\stock_model.php on line 63 where line 63 is this "compcode" => $result[$i][0],
  2. sir(s) attached is the data that i was trying to read. [attachment deleted by admin]
  3. sir this was the response from the codeigniter. I was trying to extract some jumbled data from a text file and then input them in mysql... btw this is the original function before i even put it on the my model in CI. it use to work by running it alone $var_array_parent = explode("\n", $handle); foreach ($var_array_parent as $value) { $var_array = explode(";", $value); $a = array_chunk($var_array, 4); } foreach($a as $k=>$v) { $temp = explode(' ', $v[1]); unset($a[$k][1]); $a[$k][] = $temp[0]; $a[$k][] = $temp[1].$temp[2]; } echo '<pre>'.print_r($a, true).'</pre>';
  4. hi, here's my code $handle = read_file($txt); $var_array_parent = explode("\n", $handle); foreach($var_array_parent as $value) { $var_array = explode(";", $value); $a = array_chunk($var_array, 4); } foreach($a as $k=>$v) { $temp = explode(' ',$v[1]); unset($a[$k][1]); $a[$k][] = $temp[0]; $a[$k][] = $temp[1].$temp[2]; } $b = print_r($a,true); for($i=0;$i<count($a);$i++){ $data = array( "compcode" => $a[$i][0], "price" => $a[$i][4], "percent" => $a[$i][5], "compname" => $a[$i][2], "volume" => $a[$i][3]); $this->db->insert('stocks',$data); when am trying to insert it in the db..it returns A PHP Error was encountered Severity: Notice Message: Undefined offset: 1 Filename: models/stock_model.php Line Number: 53 [ A PHP Error was encountered Severity: Notice Message: Undefined offset: 1 Filename: models/stock_model.php Line Number: 56 A PHP Error was encountered Severity: Notice Message: Undefined offset: 2 Filename: models/stock_model.php Line Number: 56 what should i do? please help with the coding logic
  5. i have fixed the code slightly to reg-group them $var_array_parent = explode("\n",$handle); foreach($var_array_parent as $value){ $var_array = explode(";",$value); $a = array_chunk($var_array,4); echo "<pre>",print_r($a),"</pre>"; } output Array ( [0] => Array ( [0] => ABA [1] => 0.97 0.00 % [2] => Abacus A [3] => 50,000 ) [1] => Array ( [0] => ABS [1] => 22.00 1.1494 % [2] => ABS-CBN [3] => 60,700 ) [2] => Array ( [0] => ABSP [1] => 22.25 1.1364 % [2] => ABS-CBN PDR [3] => 78,500 ) [3] => Array ( [0] => AC [1] => 280.00 -1.7544 % [2] => Ayala Corp [3] => 517,760 ) one last problem is that the price and percentage are sticking at each other on each of the company with key == 1 can you help me sir(s) how to solve this one last thing ?
  6. sir there's something wrong, the sample data output should be example data: ABA ;0.97 0.00 %;Abacus A ;50,000 ; ABA = Company Code 0.97 = Price 0.00% = Percent_change Abacus A = Company Name 50,000 = Volume so a company has - company code - price - percent_change - company name - volume I altered your code like this $handle = file_get_contents("textfile.txt"); $var_array_parent = explode("%",$handle); foreach($var_array_parent as $value){ $var_array = explode(";",$value); echo "<pre>",print_r($var_array),"</pre>"; } and the output seem separating the "name" of the company from each of the company right after the percent because of the explode function ? Array ( [0] => . [1] => Stock Update as of [2] => . [3] => TUE JUL 21, 2009 12:11:00 PM [4] => ABA [5] => 0.97 0.00 ) 1 Array ( [0] => [1] => Abacus A [2] => 50,000 [3] => ABS [4] => 22.00 1.1494 ) 1 Array ( [0] => [1] => ABS-CBN [2] => 60,700 [3] => ABSP [4] => 22.25 1.1364 ) 1 Array ( [0] => [1] => ABS-CBN PDR [2] => 78,500 [3] => AC [4] => 280.00 -1.7544 ) 1
  7. hi, I have a problem can you sir(s) tell me how to extract data from a messy text file and put it in mysql ? basically the sample data is something like this .;Stock Update as of ;.;TUE JUL 21, 2009 12:11:00 PM;ABA ;0.97 0.00 %;Abacus A ;50,000 ;ABS ;22.00 1.1494 %;ABS-CBN ;60,700 ;ABSP ;22.25 1.1364 %;ABS-CBN PDR ;78,500 ;AC ;280.00 -1.7544 %;Ayala Corp ;517,760 ;ACPR ;105.00 0.00 %;Ayala Pref. B ;5,920 ;AEV ;6.70 1.5152 %;Aboitiz ;278,000 ;AGI ;3.75 -2.5974 %;Alliance Global ;10,685,000 ;AJO ;0.0525 5.00 %;Ajo.Net ;100,000 ;ALCO ;0.15 0.00 %;Alco ;30,000 ;ALHI ;6.40 -1.5385 %;Anchor Land ;2,000 ;ALI ;8.90 -1.1111 %;Ayala Land ;9,422,000 ;AMC ;4.70 -6.00 %;Alaska Milk ;266,000 ;ANS ;2.34 0.00 %;Anscor ;239,000 ;AP ;5.80 -1.6949 %;Aboitiz Power ;7,544,000 ;APC ;0.36 2.8571 %;APC Group ;5,430,000 ;APO ;1.16 -1.6949 %;Anglo-Phil Hldg ;53,000 ;APX ;2.85 -3.3898 %;Apex Mining A ;5,000 ;APXB ;2.90 -1.6949 %;Apex Mining B ;47,000 ;AR ;0.0046 0.00 %;Abra Mining ; how am I gonna input that inside a db if its that jumbled. first thing i did was to try the readfile function $handle = "textfile.txt"; $handle = readfile($handle); echo $handle; but then the whole jumble words were just printed on the browser, how am i output the data something like this ? example data: ABA ;0.97 0.00 %;Abacus A ;50,000 ; ABA = Company Code 0.97 = Price 0.00% = Percent_change Abacus A = Company Name 50,000 = Volume
  8. sasori

    ZF 500 error

    I changed my mind. am gonna be using code igniter for noobs instead ROFL ..case solved.
  9. sasori

    ZF 500 error

    I managed to tweak the AllowOveride stuff. but then some methods are depracated Notice: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead in C:\xampp\htdocs\gamenomad\library\Zend\Loader.php on line 207 Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\xampp\htdocs\gamenomad\library\Zend\Controller\Dispatcher\Standard.php:242 Stack trace: #0 C:\xampp\htdocs\gamenomad\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\xampp\htdocs\gamenomad\public\index.php(22): Zend_Controller_Front->dispatch() #2 {main} thrown in C:\xampp\htdocs\gamenomad\library\Zend\Controller\Dispatcher\Standard.php on line 242
  10. sasori

    ZF 500 error

    changing that configuration you stated didn't help. but with regards to the document root, yes, "htdocs" is my xampp's document root, i named the folder "mysite" and tweaked my host and vhosts so that I can just type a shortcut on my browser like "http://mysite" but then 500 error is showing up
  11. sasori

    ZF 500 error

    I have the .htaccess file that contains these stuffs RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCOnd %{REQUEST_FILENAME} -d [ RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ /index.php [NC,L] my folder tree is like this htdocs/mysite/ /application/ =>/controllers/ =>/views/ =>/scripts/ =>/index/ /library/ /public/ =>/css/ =>/images/ =>/javascript/ .htaccess .index.php is that correct ?
  12. sasori

    ZF 500 error

    hi sirs, am trying to run ZF in my xampp. mod_rewrite is enabled and apache was restarted and yet am getting 500 error, what should i do ?
  13. I read some other tutorials from googling, is curl only use for posting ? or it can also be used for rendering/retrieving the data that has been pulled from other site ?
  14. thanks for the tutorial sir, but it seems like it doesn't tell anything how to do some PHP + REST
  15. I was asked to create a class that will enable the user to pull data and post a data using their site to a video posting website. the problem is i don't really know what to do here's my first code $url = "http://www.howcast.com/videos/230309-How-To-Roll-Pastry-Dough.xml?api_key=[api key here]"; $response = file_get_contents($url); echo $response; running that code renders a bunch of string on the browser, what the best thing to do ? ( before posting this, i was already searching google for a rest + php tutorial, but there's a nosebleeding limited tutorial on the net)
  16. ok I'm wrong. sorry.. i won't post any exam question again..except real coding trouble. tnx
  17. im not cheating sir. actually i posted 2 question for my own review..i won't post another one..sorry for the mess
  18. I'm not actually cheating Sir, I just want to 'learn' and improve my weakpoint areas, ofcourse with the help of experts in here.. but speaking of cheating. some zce mentioned "cheat" on mock exam http://mcloide.wordpress.com/2008/09/18/zend-exam-tips-scoring-system/ search for the keyword "cheat" and you'll see it from the thread..
  19. but for me "reviewing" == "studying", I'm sorry for the wrong post. (but i wouldn't have postid it here if i knew what the answer should be.. sorry)
  20. but sir, its just a mock exam question for me, I am currently reviewing, and am just seeking for experts opinion/answers about it this is not related to the real one right?
  21. please give me the correct 2 answers 1) Unlike a database such as MySQL, SQLite columns are not explicitly type. Instead, SQLite categorizes data into which of the following categories ? a) textual b) unicode c) numeric d) binary e) constant
  22. thanks alot for the reply sir, that helped a million tons
  23. it's been awhile since I last posted some php coding question here. I got a new one right now. 1) what are the 4 MVC components for web development? is it a) model,view,controller, validation b) model, view, controller, front controller please tell me which is the correct one.. am kinda confused LOL
  24. wow,nice..thanks for this sir ^^,
  25. If you don't need to put it into a database, I'd recommend you use json_encode() for it is much more what you'd use without needing to set it into a special array, json_decode would place the file contents into an array after. http://ca.php.net/json_encode sir, can you give me an example of this?,,you can use the code i posted
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.