我会计算ID存在的次数,以便将我的表格的单元格与rowspan合并。我认为要进行查询,但资源过于密集,页面显示速度很慢。我尝试计算值出现的次数" array_count_values"但它不起作用。我使用Wordpress进行预告。
查询结果
BAKU (ID:3138) RACE 1
BAKU (ID:3138) RACE 2
MONZA (ID:1) RACE
....
预期结果
BAKU (ID:3131) RACE 1
RACE 2
MONZA (ID:1) RACE
....
查询
$sqlcalendarcurrentweek=$wpdb->get_results("SELECT race.entrant, team_nat, chassis.chassis, engine.engine, driver.driver, driver_code, driver_nation,
calendar_code, calendar_season, timetable_date, circuit_town, calendar_nation, circuit_code,
season_name_short, calendar_circuit, abbreviation.abbreviation AS timetabletype,
maker.maker_code AS makertyrecode, race.race_timetable_code, maker.maker AS makertyre, race.race_class, race.race_class_name,
id_circuit, id_season, chassis_code, engine_code, season_code, race.co_driver,
abbreviation_1.abbreviation_active, abbreviation_1.abbreviation$extensionlang AS typeresult,
abbreviation_2.abbreviation$extensionlang AS timetablereason
FROM circuit, calendar, timetable, abbreviation, race, season, driver, chassis, engine, maker, abbreviation AS abbreviation_1, abbreviation AS abbreviation_2
WHERE calendar.id_calendar = timetable.timetable_calendar
AND driver.id_driver=race.driver
AND timetable.timetable_result=abbreviation_1.id_abbreviation
AND timetable.timetable_reason=abbreviation_2.id_abbreviation
AND season.id_season = calendar.calendar_season
AND circuit.id_circuit=calendar.calendar_circuit
AND abbreviation.id_abbreviation = timetable.timetable_type
AND abbreviation.abbreviation LIKE 'race%'
AND race.RE='1'
AND maker.id_maker=race.tyre
AND chassis.id_chassis=race.chassis
AND engine.id_engine=race.engine
AND timetable.id_timetable = race.race_timetable_code
AND week(timetable_date)='".$currentweek."' AND timetable_date LIKE '".$currentweekyear."%'
ORDER BY circuit_town ASC, calendar_code ASC, timetable_date ASC");
$countidcircuit=array();
foreach($sqlcalendarcurrentweek as $rowcalendarcurrentweek):
$countidcircuit[] = $rowcalendarcurrentweek->id_circuit;
$resultcountidcircuit= array_count_values($countidcircuit);
$countresultcountidcircuit= $resultcountidcircuit[$rowcalendarcurrentweek->id_circuit]
var_dump($countresultcountidcircuit);
echo '<td rowspan="'.$countresultcountidcircuit.'">'.multiplecountry($rowcalendarcurrentweek->calendar_nation,'').' <a href="'.get_home_url().'/'.pll__('circuits').'/'.$rowcalendarcurrentweek->circuit_code.'/" title="'.$rowcalendarcurrentweek->calendar_circuit_name.'">'.$rowcalendarcurrentweek->circuit_town.'</a></td>';
....
endforeach;
var_dump结果
array(1) {
[3138]=> int(1)
}
array(2) {
[3138]=> int(1) [1]=> int(1)
}
如何让2到巴库和1为蒙扎?