Hey guys can you help me i need to convert this query in to an PHP code.
set @sql = (
select group_concat(distinct
concat(
"sum(case when `test_id`='",test_id, "' then `points` ELSE '0' end) as `", `test_id`, "`"
)
)
from test_answered WHERE checked = '1'
);
set @sql = concat("select url_id, ", @sql, " from test_answered group by `url_id`");
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
i can't try that code in php. By the way im using PDO. So this will be hard on me.
I try this code
$quer = "SELECT url_id,test_id,points,GROUP_CONCAT(DISTINCT CONCAT('SUM(CASE WHEN test_id = 'test_id' THEN points ELSE '0' END))') AS test FROM test_answered WHERE checked = '1' GROUP BY id";
$arr4 = ['test_id'=>$array];
$data3 = $test_a->query($quer);
But it give me this
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' THEN points ELSE '0' END))') AS test FROM test_answered WHERE checked = '1...' at line 1