Php 循环遍历sql查询的结果
我有一个返回多行的查询。我似乎找不到在$params数组中存储行的方法。是否有方法循环抛出并将每一行存储在$params变量中Php 循环遍历sql查询的结果,php,mysql,arrays,Php,Mysql,Arrays,我有一个返回多行的查询。我似乎找不到在$params数组中存储行的方法。是否有方法循环抛出并将每一行存储在$params变量中 $aResult = $db->exec_sql($sql); $params = array( // where $aResult[o]'' would be row 1 [1] row 2 etc. // 'store_id' => $aResult[]['iStoreID'], 'user_id' => $aResult[]['i
$aResult = $db->exec_sql($sql);
$params = array(
// where $aResult[o]'' would be row 1 [1] row 2 etc. //
'store_id' => $aResult[]['iStoreID'],
'user_id' => $aResult[]['iUserID'],
'store_name' => $aResult[]['cStoreName'],
'store_url' => $aResult[]['cStoreURL'],
'rid' => $aResult[]['cRID'],
'affiliate_id' => $aResult[]['iAffiliateID'],
'team_id' => $aResult[]['iTeamID'],
'bizOP' => $aResult[]['cDefaultBizOpp'],
'showBizOPp' => $aResult[]['iShowBizOppDropdown'],
'boPosting' => $aResult[]['iEnableBOPosting'],
'brandinglevel' => $aResult[]['iBrandingLevel']
);
谢谢你的帮助我就是这样用的
$aResult = mysql_query($sql);
while($data = mysql_fetch_array($result)) {
'store_id' = $aResult['iStoreID'];
}
在不知道结果数组的确切结构的情况下,至少这是一个想法,我想您需要这样的东西:
<?php
$params = array();
$mapping = array(
'store_id' => 'iStoredID',
'user_id' => 'iUserID',
// and so on...
);
foreach ($aResult as $row) {
$tempRow = array();
foreach ($row as $key => $value) {
$paramKey = isset($mapping[$key]) ? $mapping[$key] : $key;
$tempRow[$paramKey] = $value;
}
$params[] = $tempRow;
}
就这么简单:
$params = array();
foreach($aResult as $row) {
$params[] = array(
'store_id' => $row['iStoreID'],
'user_id' => $row['iUserID'],
'store_name' => $row['cStoreName'],
'store_url' => $row['cStoreURL'],
'rid' => $row['cRID'],
'affiliate_id' => $row['iAffiliateID'],
'team_id' => $row['iTeamID'],
'bizOP' => $row['cDefaultBizOpp'],
'showBizOPp' => $row['iShowBizOppDropdown'],
'boPosting' => $row['iEnableBOPosting'],
'brandinglevel' => $row['iBrandingLevel']
);
}
你能告诉我们exec_sql返回什么吗?var_dump($aResult)代码>=?40=[包含4个元素的数组]0=[包含14个元素的数组]iInvoice=“”yAmt=“”cNameF=“”cNameL=“”cEmail=“”。。。这就是sql正在做的事情的转储。显然,有更多的列和数据被删除了,但我认为这是必要的。感谢您为了让人们更容易阅读,您可以使用并使用转储更新。停止使用mysql_*函数。此扩展已被弃用,并将很快从php中删除。改用mysqli或pdo。