![](/img/trans.png)
[英]PHP script doing large amount of DNS queries - best way for handling it
[英]Best way to doing this in php
我正在從數據庫中獲取數據,並假設表中有23列,然后我必須寫23行設置值。 還有其他簡短的方法嗎?
在下面的示例中,只有15列,我寫了15行。 有什么辦法嗎?
while( $row = mysql_fetch_array( $export ) )
{
$line = '';
$line.=setValue($row[0]);
$line.=setValue($row[1]);
$line.=setValue($row[2]);
$line.=setValue($row[3]);
$line.=setValue($row[4]);
$line.=setValue($row[5]);
$line.=setValue($row[6]);
$line.=setValue($row[7]);
$line.=setValue($row[8]);
$line.=setValue($row[9]);
$line.=setValue($row[10]);
$line.=setValue($row[11]);
$line.=setValue($row[12]);
$line.=setValue($row[13]);
$line.=setValue($row[14]);
}
while( $row = mysql_fetch_array( $export ) )
{
$line = '';
foreach($row as $value) {
$line.=setValue($value);
}
}
我不太確定這是否是您要查找的內容,但是可以使用如下所示的for循環:
while( $row = mysql_fetch_array( $export ) )
{
$line = '';
for($i = 0; $i < 15; $i++)
{
$line.=setValue($row[$i]);
}
}
while( $row = mysql_fetch_array( $export ) )
{
$line = '';
for($i = 0; $i < 15; $i++) {
$line .= setValue($row[$i]);
}
}
那是一種方法。 還有其他 您可以將“ 15”替換為返回數組的計數。 這樣,for循環將迭代直到數組結束。
起伏,大聲笑,為時已晚...
雖然你可以做類似...
while ($row=mysql_fetch_array($export)) {
$line=array();
$line=array_map('setValue',$xport);
$line=implode('',$line);
}
....它的結構很雜亂-它假設查詢將返回定義非常明確的結果集,並且結果集的結構及其后續應用程序被放置了; 作為一般經驗法則,永遠不要使用mysql_fetch_array-改用mysql_fetch_assoc。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.