2013-09-21 66 views
-2
<?php 
include('database.class.php'); 
$sql = new Database(NULL); 

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true); 
$dump = array(); 
foreach ($ids as $index as $id) 
     $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1'; 
$DumpFile = 'ids.txt'; 

if(file_exists($DumpFile)) { 
     unlink($DumpFile); 
} 
file_put_contents($DumpFile, implode("\r\n", $dump)); 
die(count($dump).' ids were dumped into the list.'."\n"); 
?> 

我檢查並重試很多事情,我只是不明白什麼是錯的。語法錯誤,意外的T_AS,期待')'

+1

哪裏是你的問題來表示? – BlitZ

回答

8
foreach ($ids as $index as $id) 

應該是:

foreach ($ids as $index => $id) 
+0

爲foreach()提供的無效參數是我現在得到的。 –

+0

如果你'var_dump($ ids)'有可能是布爾型錯誤而不是數組。它看起來像你的SQL格式不正確。它應該看起來像'SELECT id FROM table'。 –

2

這是錯誤的:

foreach ($ids as $index as $id) 

這不是正確的語法,你不使用$index任何地方。只要使用此:

foreach ($ids as $id) 

Manual page about foreach

0

foreach是錯誤的。像這樣嘗試。 鍵 - 值成對使用,此操作=>

<?php 
include('database.class.php'); 
$sql = new Database(NULL); 

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true); 
$dump = array(); 
foreach ($ids as $index=>$id) 
     $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1'; 
$DumpFile = 'ids.txt'; 

if(file_exists($DumpFile)) { 
    unlink($DumpFile); 
} 
file_put_contents($DumpFile, implode("\r\n", $dump)); 
die(count($dump).' ids were dumped into the list.'."\n"); 
?> 
0

正確的代碼

<?php 
include('database.class.php'); 
$sql = new Database(NULL); 

$ids = $sql->select('*', '`ids` ORDER BY `UserId` ASC', NULL, NULL, NULL, true, true); 
$dump = array(); 
foreach ($ids as $index => $id) 
     $dump[] = $id['UserId'].' | REGLINK - http://xat.com/web_gear/chat/register.php?UserId='.$id['UserId'].'&k2='.$id['k2'].'&mode=1'; 
$DumpFile = 'ids.txt'; 

if(file_exists($DumpFile)) { 
     unlink($DumpFile); 
} 
file_put_contents($DumpFile, implode("\r\n", $dump)); 
die(count($dump).' ids were dumped into the list.'."\n"); 
?> 
相關問題