Fra mySQL til php, SET @a :=0;
Et udtræk fungerer perfekt direkte i mySQL.Jeg vil gerne have udtrækket sat ind i en php-side.
Altså i stil med $q = mysql_query("SELECT....")
while($r = mysql_fetch_array($q)) {...}
Det driller, specielt første linje, SET @a :=0;
Når, her kommer koden som altså virker fint direkte i mySQL'en:
SET @a :=0;
SELECT target AS Klub, COUNT( * ) AS Kampe, MIN( DATE ) AS Fra_dato, MAX( DATE ) AS Til_dato, DATEDIFF( MAX( DATE ) , MIN( DATE ) ) AS dage, SUM( points ) AS POINT, SUM( points =3 ) AS Win, SUM( points =1 ) AS Draw, SUM( goalf ) AS Mal_for, SUM( goala ) AS Mal_imod, SUM( goalf - goala ) AS Dif
FROM (
SELECT IF( points >0, @a , -1 * @a := @a +1 ) AS snum, target, DATE, points, goalf, goala
FROM matchtarget
ORDER BY target, DATE
) AS q
GROUP BY target, snum
ORDER BY kampe DESC , POINT DESC , dif DESC
LIMIT 10 ;