Reputation: 762
I want to use php mysqli function, to query this:
SET @rownum = 0, @rank = 1, @prev_val = NULL;
SELECT @rownum := @rownum + 1 AS row,
@rank := IF(@prev_val!=score,@rownum,@rank) AS rank,
userid,
@prev_val := score AS score
FROM (
SELECT userid, sum(amount) as score
from leads WHERE date(time) >= '2013-08-15'
group by userid
) exodus_entries
ORDER BY rank asc LIMIT 0,100;
I tried using the mysqli_query(link, query); function, but no luck, any help?
Upvotes: 0
Views: 2283
Reputation: 562330
There is no need to use multi-query, and you risk security problems whenever you use multi-query.
The values for you user variables @rownum, @rank, @prev_val will remain in effect for the second query, as long as you run both query in the same connection.
So just run mysqli_query("SET ...");
and then run mysqli_query("SELECT...");
separately. It's much simpler to do this, and avoids at least one security risk.
Regarding your error:
mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given
Always check the return value of mysqli_query(). It will return false if there's an error. And of course you can't run mysqli_fetch_row(false);
Upvotes: 3