@@ -97,19 +97,32 @@ function &load_all_program_data($start_time, $end_time, $chanid = false, $single
97
97
trigger_error ("load_all_program_data() attempted with out any channels " , FATAL );
98
98
$ these_channels = implode (', ' , $ these_channels );
99
99
// Build the sql query, and execute it
100
+ // The weird stuff with pr1 and pr2 is to eliminate the mutiple ratings
101
+ // per program which causes duplicates to be found.
102
+ // This code selects the "rater" with the highest name alphabetically,
103
+ // so for example where raters available for a program are CHVRS ClassInd and VCHIP,
104
+ // it selects VCHIP.
100
105
$ query = 'SELECT DISTINCT program.*,
101
106
UNIX_TIMESTAMP(program.starttime) AS starttime_unix,
102
107
UNIX_TIMESTAMP(program.endtime) AS endtime_unix,
103
- IFNULL(programrating .system, "") AS rater,
104
- IFNULL(programrating .rating, "") AS rating,
108
+ IFNULL(pr1 .system, "") AS rater,
109
+ IFNULL(pr1 .rating, "") AS rating,
105
110
channel.callsign,
106
111
channel.channum
107
112
FROM program USE INDEX (id_start_end)
108
- LEFT JOIN programrating USING (chanid, starttime)
109
- LEFT JOIN channel USING (chanid)
110
- LEFT JOIN credits USING (chanid, starttime)
113
+ LEFT JOIN programrating pr1
114
+ on program.chanid = pr1.chanid
115
+ and program.starttime = pr1.starttime
116
+ LEFT OUTER JOIN programrating pr2
117
+ on program.chanid = pr2.chanid
118
+ and program.starttime = pr2.starttime
119
+ and pr2.system > pr1.system
120
+ LEFT JOIN channel on channel.chanid = program.chanid
121
+ LEFT JOIN credits
122
+ on program.chanid = credits.chanid
123
+ and program.starttime = credits.starttime
111
124
LEFT JOIN people USING (person)
112
- WHERE ' ;
125
+ WHERE pr2.system is null and ' ;
113
126
// Only loading a single channel worth of information
114
127
if ($ chanid > 0 )
115
128
$ query .= ' program.chanid= ' .$ db ->escape ($ chanid );
0 commit comments