It's still a problem related to correction-the exception is known.

Source: Internet
Author: User
It's still a problem of correction-the error has been known, but I don't know how to change PHPcode & lt ;? PhpfunctiongetCSVdata ($ filename) {$ row1; the first line starts if ($ handlefopen ($ filename, & quot; r & quot ;))! False) {whi is an error correction problem-the error is known.
I don't know how to change it.

PHP code
  
  $ V) {if ($ k = $ c) // corresponding field {$ data [$ v] = $ dataSrc [$ c] ;}}} if (! Empty ($ data) {$ dataRtn [] = $ data; unset ($ data) ;}$ row ++ ;}fclose ($ handle); return $ dataRtn ;}} function print_array ($ data) // error in this function {$ row = count ($ data); $ column = count ($ data [0]); echo $ row; echo $ column; echo"
  
  
   
   
"; For ($ I = 0; $ I <$ row; $ I ++) {echo"
   
   
      "; For ($ j = 0; $ j <$ column; $ j ++) {echo" 
     ";} Echo" 
    ";} Echo" 
   
"; Echo $ data [$ I] [$ j]; echo"
";}$ AData = getCSVdata('test.csv '); // print_r ($ aData); print_array ($ aData);?>


This is because you want to read the relevant table information in a file similar to an excel file from a csv file and display it in the way of index number [$ I] [$ j.
But the problem is that $ j is not the index of the column in the real data table, because in my file, the names of each column are actually "salary 1" "salary 2" "salary 3 "...
Such a Chinese name. So the error "Undefined offset: 0 in C: \ inetpub \ wwwroot \ test \ fileRead. php on line 54" is displayed.

So how can I solve this problem: when I don't know the index key of a column in advance, how can I retrieve them by index number?
In actual functions, I need to query the database based on the column name, and insert the value of the corresponding column into the column of the corresponding database table name,
For example, if $ data [I] ["payroll 1"] is inserted into the "payroll 1" column of the data table, you must be able to extract this string "payroll 1, in addition, the corresponding array element must also be obtained separately.

------ Solution --------------------
Use foreach loop
You 'd better post $ aData with var_export ($ aData)

------ Solution --------------------
Traverse the array, commonly used

Foreach ($ arr AS $ k => $ v) // $ k is the subscript and $ v is the value.
{

}

Or you can use the while list to traverse the array.
------ Solution --------------------
Foreach ($ data [$ I] as $ k => $ v) // $ k is the column name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.