Jump to content

How do i link 2 tables in php

- - - - -

  • Please log in to reply
4 replies to this topic

#1
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
hi friends,

im having a problem do i need to create 2 tables or 2 database for this?

i want to create a game where participants need to register before they could guess.
my table structure: (i dont know if its right)

Registration table:
userid(auto), username, fname, lname, password

guess table:
userid(auto), guess1, guess2, guess3, date_entry(auto)

the link for the user and the game is the userid

and i need to create a display(admin) for the game.

sample output:
Name Guess1 guess2 guess3 date entry
james 57 54 49 Apr. 30, 2011

how do i create the sql for the table and the query for linking the 2 tables?

Thank you. hope you could help me.

#2
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
any help?
Thank you.

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
SELECT name, guess1, guess2, guess3, date_entry 

FROM registration r

JOIN guess g ON r.userid = g.userid

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#4
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
hi,

how will php know if the 3 numbers entered by the currently login user, know that it is his guess.

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
add a where statement on
WHERE r.userid='$loggedinid'
at the end of that statement where $loggedinid is the id of logged in user.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users