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

JQuery Autocomplete without using label, value, id -

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

JAVA - what is the difference between void and boolean methods? -