php - SQL Syntax Error. Looks like i miss something -


here sql code combined php

$query = sprintf("select sum( value ) totalvalue ( select * answers user_id='%s' , test_id ='%s' order answers.id desc limit '%s' ) subquery", $user_id, mysql_real_escape_string($test_id), $num_of_q); 

and here error:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near ''40' ) subquery' @ line 8

what problem here?

remove '' limit value , use %d when using numbers:

$query = sprintf("select sum( value ) totalvalue ( select * answers user_id='%s' , test_id ='%s' order answers.id desc limit %d ) subquery", $user_id, mysql_real_escape_string($test_id), $num_of_q); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -