0

我有一个返回多行的查询。我似乎找不到将行存储在 $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[]['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']
);

谢谢您的帮助

4

3 回答 3

2

就如此容易:

$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']
    );
}
于 2013-06-14T21:45:30.243 回答
0

在不知道结果数组的确切结构的情况下,我猜你需要这样的东西:

<?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;
}
于 2013-06-14T21:43:36.247 回答
-1

我这样用

$aResult = mysql_query($sql);

while($data = mysql_fetch_array($result)) {
     'store_id' = $aResult['iStoreID'];
}

至少是这样的想法

于 2013-06-14T21:37:20.707 回答