burge124 Posted March 2, 2008 Share Posted March 2, 2008 hi need help completing this query... count from question where correctanswer is A and "chapterid" = 1 $correctanswer = "SELECT count(*) FROM question WHERE CorrectAnswer = 'A'"; is it a join i need??? Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/ Share on other sites More sharing options...
Psycho Posted March 2, 2008 Share Posted March 2, 2008 There's no way for us to know if a JOIN is needed since we have no clue as to the structure of your database. Are you querying data from multiple tales? If so, then a JOIN would be needed. But if all the data is in one table then it would look something like this: SELECT count(*) FROM question WHERE CorrectAnswer = 'A' AND chapterid = 1 Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/#findComment-482001 Share on other sites More sharing options...
burge124 Posted March 3, 2008 Author Share Posted March 3, 2008 hi, yes thanks thats fine... although my next query is from two tables, select all from table question "CorrectAnswer" and table userattempt field "Result" are the same value "SELECT * FROM question WHERE CorrectAnswer = userattempt = ???"; or would this require an if else statment? if correctanswer = result echo true, if correctanswer != result echo false if else echo unanswered??? thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/#findComment-482013 Share on other sites More sharing options...
burge124 Posted March 3, 2008 Author Share Posted March 3, 2008 sorry meant to type select all from table question field "CorrectAnswer" join table userattempt field "Result" are the same value Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/#findComment-482022 Share on other sites More sharing options...
burge124 Posted March 3, 2008 Author Share Posted March 3, 2008 any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/#findComment-482082 Share on other sites More sharing options...
Psycho Posted March 4, 2008 Share Posted March 4, 2008 Again, no way to respond without knowing your table structures. I'm not a clairvoyant. Please list the fields in the tables you need to get data from, identifying the foreign keys as applicable. Also, your explanatin of the data you are after is vague at best. Please be VERY specific. Quote Link to comment https://forums.phpfreaks.com/topic/94089-need-help-completing-query-plz/#findComment-482813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.