Page 1 of 1
Pulling up var from another table
Posted: Wed Nov 15, 2006 12:20 am
by 4Boredom
I am creating an articles section on my website, where any user can submit one. I need to code it so that I know the user # that submitted it.. So I need:
However, Userid is in the basic table which was not in tho form submitted on the previous page. And on the registration form for the other page I just set that to auto_increment, where here it shouldn't.
How do I pull up $userid from a table named 'basic'.
Posted: Thu Nov 16, 2006 1:08 am
by 4Boredom
upping this as it has been over the 24 hour time frame I have to wait to do so.
Posted: Thu Nov 16, 2006 1:23 am
by ryuuka
if the user name is in the table where the usernumbers are located you can use something like this:
Code: Select all
select usernumber, username
from basic_table
where (username = '$userid')
or you could use join to compare the username to the userID
goodluck
Posted: Thu Nov 16, 2006 3:34 am
by 4Boredom
no... they are in different tables....
I need to pull userid from basic... and save it as usernumber on a dif table?
Posted: Thu Nov 16, 2006 4:19 am
by aaronhall
In the articles table, create a column that stores a copy of the auto-incrementing ID from the users table. When the article is submitted, insert the user's ID into the articles table along with the rest of the article information. When you are displaying the articles and you also want to display the user's information, write a function that fetches the username from the users table with an ID that matches the copy in the articles table.
Code: Select all
# if $userid is the user ID stored in the articles table:
SELECT username FROM users WHERE id = '$userid';
Posted: Thu Nov 16, 2006 7:15 pm
by 4Boredom
Writing a copy wont work here.
One user should be able to submit multiple articles.
Thers not a way I can just call up $userid and then make $usernumber a copy of that data (while processing article)?
Posted: Thu Nov 16, 2006 7:21 pm
by volka
Please show your table definitions in more detail (e.g. as sql dump)
Posted: Sun Nov 19, 2006 7:27 pm
by 4Boredom
Code: Select all
$query = "SELECT userid FROM basic";
$result = mysql_query($query) or die ($ERROR_MSG . mysql_error());
$userid = $usernumber;
This still posts the UserId as 0...
and as far as table definitions...
$userid is in the table 'basic'.. thats where I need to call from
Posted: Sun Nov 19, 2006 7:29 pm
by 4Boredom
nevermind... the select function worked
I needed to switch Usernumber and userid in the last line
WORKS NOW!
Thank you to all who responded!