Virker direkte i mySQL, ikke gennem php
Følgende afvikles fint direkte i mySQL-dbSET @snum:=0;
SELECT navn, DATE_FORMAT(MIN(dato), '%Y-%m-%d') AS fra, DATE_FORMAT(MAX(dato), '%Y-%m-%d') AS til, COUNT(*) AS serie
FROM (
SELECT t1.*, IF(goal, @snum,-1*(@snum:=@snum+1)) AS maal2
FROM (
SELECT p.dato, p.kampid, pl.spillerid AS spillerid, l.spillerid AS spiller, l.ind, l.udfor, navn, IF(!ISNULL(m.scorer), 1, 0 ) AS goal
FROM pgram AS p
JOIN lineup AS l ON p.kampid=l.kampid
JOIN player AS pl ON (l.spillerid=pl.spillerid OR l.ind=pl.spillerid OR l.udfor=pl.spillerid)
LEFT JOIN (
SELECT DISTINCT kampid, scorer FROM maalarkiv ) AS m ON (p.kampid=m.kampid AND pl.spillerid=m.scorer) ORDER BY pl.spillerid, p.dato
) AS t1
) AS t2
GROUP BY spillerid, maal2 ORDER BY serie DESC LIMIT 30;
Når jeg vil presse det gennem php, ser det således ud:
mysql_query( "SET @snum:=0" );
$sql = mysql_query("
SELECT navn, DATE_FORMAT(MIN(dato), '%Y-%m-%d') AS fra, DATE_FORMAT(MAX(dato), '%Y-%m-%d') AS til, COUNT(*) AS serie
FROM (
SELECT t1.*, IF(goal, @snum,-1*(@snum:=@snum+1)) AS maal2
FROM (
SELECT p.dato, p.kampid, pl.spillerid AS spillerid, l.spillerid AS spiller, l.ind, l.udfor, navn, IF(!ISNULL(m.scorer), 1, 0 ) AS goal
FROM pgram AS p
JOIN lineup AS l ON p.kampid=l.kampid
JOIN player AS pl ON (l.spillerid=pl.spillerid OR l.ind=pl.spillerid OR l.udfor=pl.spillerid)
LEFT JOIN (
SELECT DISTINCT kampid, scorer FROM maalarkiv ) AS m ON (p.kampid=m.kampid AND pl.spillerid=m.scorer) ORDER BY pl.spillerid, p.dato
) AS t1
) AS t2
GROUP BY spillerid, maal2 ORDER BY serie DESC LIMIT 30
") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {...........
Hvilket giver denne fejlmeddelse
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Nogen bud??