-1

MySql 查询返回一个多维数组:

function d4g_get_contributions_info($profile_id)
{
   $query = "select * from contributions where `project_id` = $profile_id";
   $row = mysql_query($query) or die("Error getting profile information , Reason : " .    mysql_error());
   $contributions = array();
   if(!mysql_num_rows($row)) echo "No Contributors";

   while($fetched = mysql_fetch_array($row, MYSQL_ASSOC))
   {
       $contributions[$cnt]['user_id'] = $fetched['user_id'];
       $contributions[$cnt]['ammount'] = $fetched['ammount'];
       $contributions[$cnt]['date'] = $fetched['date'];
       $cnt++;  
   }
   return $contributions;
}

现在我需要在调用此函数的页面中打印值。我怎么做 ?

4

1 回答 1

2

改变这样的功能:

while($fetched = mysql_fetch_array($row, MYSQL_ASSOC))
{
$contributions[] = array('user_id' => $fetched['user_id'],
                            'ammount' => $fetched['ammount'],
                            'date' => $fetched['date']);

}

return $contributions;

然后在下面尝试:

$profile_id = 1; // sample id
$result = d4g_get_contributions_info($profile_id);
foreach($result as $row){
    $user_id = $row['user_id']
    // Continue like this
}
于 2013-10-05T09:41:05.807 回答