如何使用PHP将查询放入MySQL?

时间:2015-06-08 05:21:38

标签: php mysql

如何将此查询放入我的PHP代码

SET @prev_value = NULL;
SET @rank_count = 0;
SELECT implement_id, total_implement, percent,CASE
    WHEN @prev_value = percent THEN @rank_count
    WHEN @prev_value := percent THEN @rank_count := @rank_count + 1
END AS rank
FROM goal_implement 
ORDER BY implement_id DESC LIMIT 1

1 个答案:

答案 0 :(得分:0)

<?php 
$sql = mysql_query("SELECT implement_id, total_implement, percent,CASE
    WHEN @prev_value = percent THEN @rank_count
    WHEN @prev_value := percent THEN @rank_count := @rank_count + 1
END AS rank
FROM goal_implement 
ORDER BY implement_id DESC LIMIT 1");

$result = mysql_fetch_assoc($sql);

?>