开发者

Fatal problem within my MySql queries

I'm having a problem regarding these 3 queries:

select count(*) as rec_count from test_history inner join
  test_detail on test_history.history_id = test_detail.test_history_id 
  where test_history.history_id in ({$_SESSION['history_ids']})
  and test_histo开发者_如何学编程ry.user_id = $userID

and

select count(*) as correct_answers from test_history inner join test_detail
  on test_history.history_id = test_detail.test_history_id 
  where test_history.history_id in ({$_SESSION['history_ids']}) and
  test_history.user_id = $userID and is_correct = 1

and this one

select * from test_topics inner join
  test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
  where test_topics_link.test_id in ({$_SESSION['ids_tests']}) and percentage > 0

I'm always getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ') and
test_history.user_id = 82' at line 3

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ') and
test_history.user_id = 82 and is_correct = 1' at line 2

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ')' at line 1

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near ') and percentage > 0' at
line 3


Since $_SESSION['ids_tests'], I suppose, is an array, you should write implode(',',$_SESSION['ids_test']), e.g. in PHP it should be:

$query = "select * from test_topics inner join
        test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
        where test_topics_link.test_id in (".
        implode(',',$_SESSION['ids_tests']).") and percentage > 0";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜