LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-04-2009, 03:50 PM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,010

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
strange php problem


the following is part of a program that tries to parse a csv file into a multi dimensional array for dumping to a database, ehen i uncomment the echo lines with html output it displays the information as an html table properly, however when i comment those back out and uncomment
PHP Code:
//$column_data[$rowcount][$keya]=$value; 
the program stops at at the loop, i can put echo statements in the loop and above the loop that work but nothing executes AFTER the loop
PHP Code:
$me=fopen("VEHICLES.TXT","r");
$gotten=fgetcsv($me);
//echo "<table>";
//echo "<tr>";
foreach($gotten as $key => $value) {
//echo "<th>".$value."&nbsp;</th>";
$headers[$key]=$value;
}
//echo "</tr><tr>";
$rowcount=0;
$increment=true;
//echo "me";
while (($row fgetcsv($me)) !== false) {
if (
$increment==true) {
//echo $rowcount."&nbsp;";
}
foreach(
$row as $keya => $value) {
if (
$keya==and !is_numeric($value)) {
$increment=false;
break;
} else {
$increment=true;
//$column_data[$rowcount][$keya]=$value;
//echo "<td>".$value."&nbsp;</td>";
//echo $headers[$keya]."&nbsp;";
}
}
if (
$increment == true) {
$rowcount++;
//echo "<br>";
}
//echo "</tr><tr>";


this part successfully dumps the first line of the csv (containing the table headers) to it's own array which i ultimately plan on using as one of the keys for the other array but i can't get it to work with just a simple numeric variable atm..
PHP Code:
foreach($gotten as $key => $value) {
//echo "<th>".$value."&nbsp;</th>";
$headers[$key]=$value;

any ideas?

Last edited by frieza; 03-04-2009 at 03:52 PM.
 
Old 03-04-2009, 05:23 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
Are you printing out the errors?By default they are only sent to the log file.The following at the start normaly helps:
PHP Code:
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors'true); 
Back to your problem has $column_data been set up as an array of arrays?
 
Old 03-04-2009, 05:31 PM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,010

Original Poster
Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
even with adding that, no errors are generated, and any code before or within the loop executes, but anything AFTER the loop does not
and yes, that is the idea is that it is supposed to be an array of arrays so that i can dump each line into a database
as such
Code:
header0 | header1 | header2
row0,0  |  row0,1 |  row0,2
row1,0  |  row1,1 |  row1,2
row2,0  |  row2,1 |  row2,2
etc...
correction
the following error
Code:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 24 bytes) in /var/www/html/csv/index.php on line 22

Last edited by frieza; 03-04-2009 at 05:33 PM.
 
Old 03-04-2009, 05:38 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,010

Original Poster
Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
fixed it, thx, it was a memory size error, increased the memory limit to 64M and it works now
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange value of variable after a php form jeanpba Linux - Software 0 11-15-2005 02:38 AM
strange apache php problem lbharti Linux - Software 3 05-20-2005 10:39 AM
Strange PHP problem!!! Birgi Programming 3 03-08-2005 12:07 PM
strange, strange alsa problem: sound is grainy/pixellated? fenderman11111 Linux - Software 1 11-01-2004 05:16 PM
strange php problem dsiguy Linux - Software 2 02-18-2003 05:07 PM


All times are GMT -5. The time now is 05:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration