php - Importing data from TXT file with while loop -
my problem don´t know how finish while loop when rows imported. drupal 7.
if set while
condition: while ($row = $regs->fetchassoc())
never inside of loop.
if use condition break loop:
$cadena = array(); while (1) { $row = $regs->fetchassoc(); $cadena[] = $row; if (count($cadena)<0){ break;}
i error: fatal error: allowed memory size of 1073741824 bytes exhausted (tried allocate 64 bytes)
the full code is:
$operations = array(); $items = array(); $limit = 25; $i = 0; $regs = db_query("select * {table_import_apunte} field_processed = :processed", array(':processed' => 0)); while ($row = $regs->fetchassoc()) { if ($i < $limit) { $items[] = $row; $i += 1; } else { $operations[] = array('csvimporter_create_nodes', array($items, 'apunte')); $items = array(); $items[] = $row; $i = 1; } } $batch = array( ... );
your approach while(1) { ... }
creates infinity loop, since attaching element array 'cadena' causes count higher 0 plus count cant lower 0
you can try use foreach instead of while
foreach ($regs $row) { ... }
Comments
Post a Comment