Jump to content
php.lv forumi

kverijs darbojas, tikai ne no php!


Chepa

Recommended Posts

ir kverijs:

SET @rownum := 0; SELECT * FROM ( SELECT @rownum := @rownum+1 AS rank, user_id, points_this_month, nick, points_month FROM v_auth WHERE points_month = '92008' ORDER BY points_this_month DESC, user_id ) AS derived_table WHERE user_id = '2' LIMIT 1;

 

no phpmyadmin jams darbojas, bet palaižot no php koda atgriež erroru:

 

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 '; SELECT * FROM ( SELECT @rownum := @rownum+1 AS rank, user_id, points_this_m' at line 1

 

wtf?

Link to comment
Share on other sites

Pastāv arī iespēja to visu pārnest uz procedūru. Tas tā - ja nav pieejams mysqli modulis.

 

Un vispār - vai tik nevarēja vienkārši sadalīt to visu pa kverijiem un izpildīt atsevišķi pēc kārtas ? Man liekas, ka otrajā kverijā būs piejams pirmajā kverijā uzsetotais mainīgais.

Edited by andrisp
Link to comment
Share on other sites

Vēl var @rownum inicializāciju ielikt papildus selektā

 

SELECT * FROM ( SELECT @rownum := @rownum+1 AS rank, user_id, points_this_month, nick, points_month FROM v_auth,(SELECT @rownum:=0) as t2 WHERE points_month = '92008' ORDER BY points_this_month DESC, user_id ) AS derived_table WHERE user_id = '2' LIMIT 1 ;

Link to comment
Share on other sites

andrisp, ja biji domājis sadalīt izveidojot temporary table, tad darbojas. ty (:

 

mysql_query("SET @rownum := 0;");
mysql_query("CREATE TEMPORARY TABLE ranking as (SELECT @rownum := @rownum+1 AS rank, user_id, points_this_month, nick, points_month FROM v_auth WHERE points_month = '$points_month' ORDER BY points_this_month DESC, user_id);
");
$query3=mysql_query("SELECT * FROM ranking WHERE user_id = '2345';") or die(mysql_error());

Edited by Chepa
Link to comment
Share on other sites

×
×
  • Create New...