Jump to content

Need Help With Two Tables


Avalanche

Recommended Posts

Okay, I am making a membership system, and there are two tables for the members. One is tbl_users (has username, password, email, and rank), and the other is tbl_userinfo (has 10+ columns of other information). So, I split it up into two different tables so it wouldn\'t get to be a ginormous table.

 

The rank that I mentioned in tbl_users can be admin, user, or unset. \"Unset\" means that the account hasn\'t been verified yet, and it doesn\'t let you log in if your account is \"unset.\"

 

Now, on the page where it lists the users (but doesn\'t have the whole profile) it uses information only from the tbl_userinfo, and doesn\'t draw anything from tbl_users. However, I need it to only select users information from tbl_userinfo where their rank in tbl_users is not \"unset.\"

 

I\'m not sure exactly how I could do this with my current table setup. Would I just have to move the rank over to tbl_userinfo?

 

I you are able to understand what I mean. Thanks.

 

PS: I have an id_key in the tbl_users, and a parent_id_key in the tbl_userinfo that are identical for each account.

Link to comment
Share on other sites

Okay, I am making a membership system, and there are two tables for the members. One is tbl_users (has username, password, email, and rank), and the other is tbl_userinfo (has 10+ columns of other information). So, I split it up into two different tables so it wouldn\'t get to be a ginormous table.

 

The rank that I mentioned in tbl_users can be admin, user, or unset. \\\"Unset\\\" means that the account hasn\'t been verified yet, and it doesn\'t let you log in if your account is \\\"unset.\\\"

 

Now, on the page where it lists the users (but doesn\'t have the whole profile) it uses information only from the tbl_userinfo, and doesn\'t draw anything from tbl_users. However, I need it to only select users information from tbl_userinfo where their rank in tbl_users is not \\\"unset.\\\"

 

I\'m not sure exactly how I could do this with my current table setup. Would I just have to move the rank over to tbl_userinfo?

 

I you are able to understand what I mean. Thanks.

 

PS: I have an id_key in the tbl_users, and a parent_id_key in the tbl_userinfo that are identical for each account.

 

You simply need to join the tables together. In SQL you are always returned a \"set\" ie. a table. Joining two or more tables together creates what you could think of as a temporary table. If I understand you correctly you have two tables that you can join by id_key and parent_id_key.

 

 

So something like:

 

SELECT * FROM

table a, table b

WHERE a.id_key = b.parent_id_key AND

rank \'unset\'

Link to comment
Share on other sites

Also, would I have to put \\\"AND tbl_users.rank ...\\\"?

 

You shouldn\'t have any fields in both tables except the id (so you can join them)

 

If you don\'t want password or email selected , you can be more selective by

 

[php:1:81b203b108]<?php

SELECT tbl_userinfo.*, tbl_users.username, tbl_users.rank FROM

tbl_users, tbl_userinfo

WHERE tbl_users.id_key = tbl_userinfo.parent_id_key AND

rank!=\'unset\'

?>[/php:1:81b203b108]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.