English 中文(简体)
PHP 通知:进口数据时未明确抵消
原标题:PHP Notice: Undefined offset when importing data
  • 时间:2010-09-07 09:56:50
  •  标签:
  • php
  • offset

直到昨天晚上,这一直被罚款,来文方档案似乎发生了变化,因此,我改变了试探和校正,但我仍然有错误。

源代码定义告诉我,这些领域是:

#export_date^Aapplication_id^Alanguage_code^Atitle^Adescription^Arelease_notes^Acompany_url^Asupport_url^Ascreenshot_url_1^Ascreenshot_url_2^Ascreenshot_url_3^Ascreenshot_url_4^Ascreenshot_width_height_1^Ascreenshot_width_height_2^Ascreenshot_width_height_3^Ascreenshot_width_height_4^Aipad_screenshot_url_1^Aipad_screenshot_url_2^Aipad_screenshot_url_3^Aipad_screenshot_url_4^Aipad_screenshot_width_height_1^Aipad_screenshot_width_height_2^Aipad_screenshot_width_height_3^Aipad_screenshot_width_height_4^B

#dbTypes:BIGINT^AINTEGER^AVARCHAR(20)^AVARCHAR(1000)^ALONGTEXT^ALONGTEXT^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(20)^AVARCHAR(20)^AVARCHAR(20)^AVARCHAR(20)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(1000)^AVARCHAR(20)^AVARCHAR(20)^AVARCHAR(20)^AVARCHAR(20)^B

我的法典

$eoldelimiter = chr(2) . "
";
$delimiter = chr(1);
    while (!feof($fp3)) {
        $line = stream_get_line($fp3,8000,$eoldelimiter); 
        if ($line[0] ===  # ) continue;  //Skip lines that start with # 
        list($export_date, $application_id, $language_code, $title, $description, $release_notes, $company_url, $suppport_url, $screenshot_url_1, $screenshot_url_2, $screenshot_url_3, $screenshot_url_4, $screenshot_width_height_1, $screenshot_width_height_2, $screenshot_width_height_3, $screenshot_width_height_4,$ipadscreenshot_url_1, $ipadscreenshot_url_2, $ipadscreenshot_url_3, $ipadscreenshot_url_4, $ipadscreenshot_width_height_1, $ipadscreenshot_width_height_2, $ipadscreenshot_width_height_3, $ipadscreenshot_width_height_4 ) = explode($delimiter, $line);
    } // end while statement

我在屏幕上的错误

PHP Notice: Undefined offset: 23 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73

Notice: Undefined offset: 23 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73 PHP Notice: Undefined offset: 22 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73

Notice: Undefined offset: 22 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73 PHP Notice: Undefined offset: 21 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73

Notice: Undefined offset: 21 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73 PHP Notice: Undefined offset: 20 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73

Notice: Undefined offset: 20 in /var/www/vhostshttpdocs/fred/daily_iapps_to_mysql.php on line 73 PHP Notice: Undefined offset: 19 in /var/www/vhosts/httpdocs/fred/daily_iapps_to_mysql.php on line 73

最佳回答

$eoldelimiter = chr(2) . "
";
$delimiter = chr(1);
$cols = array( // you can even derive this from the comment line ...if you want to.
   export_date ,  application_id ,  language_code ,  title ,
   description ,  release_notes ,  company_url ,  suppport_url ,
   screenshot_url_1 ,  screenshot_url_2 ,  screenshot_url_3 ,  screenshot_url_4 ,
   screenshot_width_height_1 ,  screenshot_width_height_2 ,  screenshot_width_height_3 ,  screenshot_width_height_4 ,
   ipadscreenshot_url_1 ,  ipadscreenshot_url_2 ,  ipadscreenshot_url_3 ,  ipadscreenshot_url_4 ,
   ipadscreenshot_width_height_1 ,  ipadscreenshot_width_height_2 ,  ipadscreenshot_width_height_3 ,  ipadscreenshot_width_height_4 
);

$fp3 = fopen( test.txt ,  rb );
$data = array();
while( !feof($fp3) ) {
  $line = stream_get_line($fp3, 8000, $eoldelimiter); 
  if (  # ===$line[0] ) {
    continue;
  }

  $row = explode($delimiter, $line);
  if ( count($row) != count($cols) ) {
    echo  wrong number of fields: ( , count($row),  )  , $line, "
";
  }
  else {
    $row = array_combine($cols, $row);
  }
  $data[] = $row;
}

而不是使用24个独立变量和清单


update: You might be interested in MySQL s LOAD DATA INFILE and/or prepared, parametrized statements, e.g. via PHP Data Objects (pdo).
But anyway, here s an example (example, not production code) for building a query string...

$eoldelimiter = chr(2) . "
";
$delimiter = chr(1);
$cols = array( // you can even derive this from the comment line ...if you want to.
   export_date ,  application_id ,  language_code ,  title ,
   description ,  release_notes ,  company_url ,  suppport_url ,
   screenshot_url_1 ,  screenshot_url_2 ,  screenshot_url_3 ,  screenshot_url_4 ,
   screenshot_width_height_1 ,  screenshot_width_height_2 ,  screenshot_width_height_3 ,  screenshot_width_height_4 ,
   ipadscreenshot_url_1 ,  ipadscreenshot_url_2 ,  ipadscreenshot_url_3 ,  ipadscreenshot_url_4 ,
   ipadscreenshot_width_height_1 ,  ipadscreenshot_width_height_2 ,  ipadscreenshot_width_height_3 ,  ipadscreenshot_width_height_4 
);
$mysql = mysql_connect(...) or trigger_error(mysql_error());
mysql_select_db( test , $mysql) or trigger_error(mysql_error($mysql));

$sql_pre=  INSERT INTO foo (  . join($cols,  , ) .  ) VALUES ( ;
$fp3 = fopen( test.txt ,  rb ) or trigger_error( fopen failed );
while( !feof($fp3) ) {
  $line = stream_get_line($fp3, 8000, $eoldelimiter); 
  if (  # ===$line[0] ) {
    continue;
  }

  $row = explode($delimiter, $line);
  if ( count($row) != count($cols) ) {
    echo  wrong number of fields: ( , count($row),  )  , $line, "
";
  }
  else {
    // the & in &$col will only work with php5+
     foreach( $row as &$col ) {   
       $col = " ".mysql_real_escape_string($col, $mysql)." ";
     }
    $sql = $sql_pre . join( , , $row) .  ) ;
    echo $sql, "
";
  }
}
问题回答

看来<代码>explode($delimiter,$line)没有给出正确的要素编号。

请注意:_r Outcome of explode,看其是否照此办理。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签