插入多个相关表

时间:2012-02-21 15:32:05

标签: php

我有两张桌子: 的 eventcategory enter image description here

initplayer enter image description here

我想要的是插入表initplayer。

为了做到这一点:     首先,我返回一个查询并创建一个关联数组

$ dbResult = mysql_query(“select * from eventcategory”);

function array_push_assoc($array, $key, $value){
$array[$key] = $value;
return $array;
}

$arrEventCategory = array();
while ($info = mysql_fetch_array($dbResult)) {
    $arrEventCategory = array_push_assoc($arrEventCategory,$info['id'],$info['eventCategory']);

}
print_r($arrEventCategory);





$ga->requestAccountData();
foreach($ga->getResults() as $result)
{

   $ga->requestReportData('30191592', array('eventCategory', 'eventAction'), array('totalEvents'), $sort_metric = null, $filter = 'eventAction==InitPlayer', $start_date = $startDate, $end_date = $startDate);
   foreach($ga->getResults() as $result2)
   {       
       $key = array_search($result2->geteventCategory(), $arrEventCategory);
       $mysql->query("insert into initplayer values(" . $result->getProfileId() . ",'" . $result . "','".$result2->gettotalEvents()."','".$startDate."',".$key.")");
   }

}

enter image description here

我想根据eventCategory插入db id:S

0 个答案:

没有答案