Jump to content

KjB31ca

New Members
  • Posts

    8
  • Joined

  • Last visited

KjB31ca's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, thanks for all the advice. I will be learning more on databases and will try to implement this to my database.
  2. I haven't worked too much using foreign keys, so I am doing some reading on implementing that. My only question is won't it be harder for me when I am looking at the populated data in the users_adventures table because I don't see a code next to the user, I would only see a q_id#? A user can have multiple codes, meaning that they have multiple "adventures" open at the same time. They can start a "DTCAP" adventure, and answer 10 questions, quit the session, and return another time and open a "CNROW" adventure, quit that session, and start another adventure and so on. I hope that makes sense how I am wording that. adventure_questions q_id q_code q_number question 1 DTCAP 1 DTCAP question 1 2 DTCAP 2 DTCAP question 2 26 CNROW 1 CNROW question 1 27 CNROW 2 CNROW question 2 51 MONFW 1 MONFW question 1 52 MONFW 2 MONFW question 2 users_adventures (Your version) - How can I tell which is DTCAP adventure, which is CNROW, MONFW,etc, without having to look at the other table??? ua_id ua_username q_id ua_score 1 kjb31ca 1 0 2 kjb31ca 27 10 3 kjb31ca 51 0 users_adventures (My old version) ua_id ua_username ua_code ua_question ua_score 1 kjb31ca DTCAP 1 0 2 kjb31ca CNROW 2 10 3 kjb31ca MONFW 1 0 users_adventures (Suggested version) ua_id ua_username ua_code q_id ua_score 1 kjb31ca DTCAP 1 0 2 kjb31ca CNROW 27 10 3 kjb31ca MONFW 51 0 Can I keep the ua_code in the users_adventures or is that just redundant and bad practice of implementing a database?
  3. YEEEEEEAAAHHHHH!!!!! Oh man, thanks so much. I just needed to add: AND q.q_code = u.ua_code. All is working good. I appreciate all the time and help.
  4. ok I put: echo $query_question; $question_info=mysql_fetch_array($query_question); OUTPUT: Resource id #7 Now I'm even more lost
  5. Here is what I think you were wanting: array(34) { [0]=> string(1) "2" ["q_id"]=> string(1) "2" [1]=> string(5) "DTCAP" ["q_code"]=> string(5) "DTCAP" [2]=> string(1) "2" ["q_number"]=> string(1) "2" [3]=> string(17) "DTCAP question #2" ["question"]=> string(17) "DTCAP question #2" [4]=> string(41) "adventures/dtcap/images/clue02-spiral.png" ["q_pic"]=> string(41) "adventures/dtcap/images/clue02-spiral.png" [5]=> string(6) "spiral" ["q_type"]=> string(6) "spiral" [6]=> string(2) "10" ["q_value"]=> string(2) "10" [7]=> string(1) "3" ["ua_id"]=> string(1) "3" [8]=> string(7) "kjb31ca" ["ua_username"]=> string(7) "kjb31ca" [9]=> string(5) "CNROW" ["ua_code"]=> string(5) "CNROW" [10]=> string(1) "1" ["status"]=> string(1) "1" [11]=> string(1) "2" ["ua_question"]=> string(1) "2" [12]=> string(2) "10" ["ua_score"]=> string(2) "10" [13]=> string(1) "0" ["q_score"]=> string(1) "0" [14]=> string(1) "0" ["ua_wrong"]=> string(1) "0" [15]=> string(1) "0" ["ua_location"]=> string(1) "0" [16]=> string(1) "0" ["ua_challenge"]=> string(1) "0" } ***Note: There are extra columns in the tables that I originally ommitted because they have no relevance to my problem, but they are shown up here. So to clarify what I am saying: The users_adventures table shows what question a particular user is on, what adventure, and their score, so they can log out and return to a previous saved session. I want to match that up with the adventure_questions table so when they return to a previous session it will match up with what question they are on. Whenever I have a session code different from DTCAP it still returns the DTCAP question from the adventure_questions table, so its not distinguishing between the session code.
  6. Ok thanks for the tips. My query works perfectly if the session code is DTCAP, but once I change the session code it will still match the question number correctly, but always return the "DTCAP question". It seems like I am properly joining the tables, but the WHERE condition isn't working. Did I set that portion up correctly?
  7. Oops, don't know how that happened, when I copied it, but it should be: WHERE u.ua_username = '$_SESSION[username]' AND u.ua_code='$_SESSION[ code ]'");
  8. I am somewhat of a newbie and think this is a simple fix, but I have been having problems and can't seem to figure it out. I am trying to JOIN two tables, but am not getting the results I would like. I am getting the correct question number displayed whenever I try different instances, but it always defaults to the "DTCAP" question (q_code). I have included the snippet of code and how the table structure looks. Any help would be greatly appreciated! ------------------------------------------------------------------------------------- //Testing to ensure that the $_SESSION['code'] is DTCAP, CNROW, or MONFW after user chooses option echo $_SESSION['code']; $query_question=mysql_query("SELECT * FROM adventure_questions q INNER JOIN users_adventures u ON q.q_number = u.ua_question WHERE u.ua_username = '$_SESSION[username]' AND u.ua_code='$_SESSION '"); $question_info=mysql_fetch_array($query_question); echo $question_info['q_number'].". ".$question_info['question']; ------------------------------------------------------------------------------------- adventure_questions q_id q_code q_number question 1 DTCAP 1 DTCAP question 1 2 DTCAP 2 DTCAP question 2 26 CNROW 1 CNROW question 1 27 CNROW 2 CNROW question 2 51 MONFW 1 MONFW question 1 52 MONFW 2 MONFW question 2 users_adventures ua_id ua_username ua_code ua_question ua_score 1 kjb31ca DTCAP 1 0 2 kjb31ca CNROW 2 10 3 kjb31ca MONFW 1 0
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.