Again my error, sory. Line 27 should be:

    $sql .= "('$current', ";

Thnx, Squidge.

now i get this

Erreur SQL ! INSERT INTO military VALUES ('15204609', 'City of Jethaya', '\'257:232', '', '0', '0', '0', '0', '0', '655', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '655', '655 berserkers'), ('15270146', 'jeth2', '\'258:233', '', '0', '0', '0', '0', '0', '16', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '16', '16 berserkers'), 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

all the 24 variable on the table military are var char with sufficient room the first one is unique primary key the 4th variable is null what am i not seing :)


ps i just noticed a coma between the 2 lines of values the coma is also at the end of the second set of values could this be it ?


Member Avatar

Strange when I use that SQL it works fine for me (I created 24 fields with varchar 255).

It seems to be the stray comma (,) at the end of your SQL.

i am still trying to figure out how it gets there



The following line:

$sql .= $i < (count($parsedArray) - 2) ? ', ' : '';

should add a comma after a set of values only when the set of values is not the one before the last (the last row is total). Please check this logic against your data. Maybe the logic should be changed.

i am afraid it will take some times before i figure the logic out
what is the value of $i ?

if i read the line right a coma is added iF $i is smaller then the amount of row in parsedarray minus 2 ?
where does i$ gets its value from ?

i am really new at this but it seems to me that the condition will always be true so a coma will always be added
problem is i got no idea how to fix it

I made a mistake, sory. The code in line 37 should be:

$sql .= $row < (count($parsedArray) - 2) ? ', ' : '';

I chnged the index names form $i to $row for more clarity but have forgoten to change it in this row. Sory for that.

Just to make sure how the logic goes, so you can check it:

The $parsedarray holds rows with data (say 5 for example) and the last row with Total information (6 all together) but we do not use the last row.

So count($parsedArray) equals 6 and indexes go from 0 to 5. But we need to proces only rows 1 to 5. (with indexes 0 to 4). Since $row represents the index and starts with 0, increasing by 1. So the logic is:

  1. process all rows except last (for($row = 0; $row < (count($parsedArray) - 1); $row++))
  2. if index is less than array lenght (e.g. 6) minus two (e.g. indexes 0 to 3) then add comma
  3. if index is not less than array lenght (e.g.6) minus two (e.g. so only the last index - 4) then do not add comma

well thanks a lot you been great both you and Diafol
now i have just one more question if i wanted to access the first data of the first row
would i do something like this print_f '$parsedarray[0][0]';

Member Avatar

That looks like the right array item, but depends what you want to do with it - print, echo, printf?

i was planning on accessing the first data of each row wich is the city id number (15270146) and from that tell the script to either make a new entry in the table (if that city is not there) or update it (if its there)
but ill look into the sql fonctions maybe there is one that already do this by default
one thing is sure tho i understand a litle bit more about arrays now ty


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.