I am making a PHP/MySQL message board but I need a little help.
I want to be able to display the author of a post.
I have one table for topics and another for members.
The problem is that in the topics table the author's ID is stored and not the members username. This ID corresponds with the ID in the members table.
I know I can use an SQL statement like:
SELECT UserName from members WHERE members.UserName = topics.Author
But the thing is that I am already executing other SQL statements to get other details of the topic
So I gues what I a m asking is how do I use the above SQL satement within another SQL statement?
Somebody PLEASE HELP, Im DESPERATE
I'd suggest visiting http://www.hotscripts.com/PHP/Tips_a...ussion_Boards/ for some tutorials.
(P.S I'd love to know how many times i've told people to go to hotscripts.com :))
Unfortunately that doesn't really help me because they are just tutorials. I need help with the specific example
I think I might be able to help, but I dont see why you would ever need a SQL statement inside anohter one...could you descirbe better please...
You need to fetch details of the topic at the same time as you fetch the author e.g.
SELECT topic.*, members.UserName FROM topic, members WHERE members.UserId=topic.Author
That query should fetch all the info about a topic and the username of the author for you.
I have a questoin...
if you have your sql statement and it goes something like this
SELECT topic.name, author.name FROM topics, authors WHERE topic.id=$id AND topic.aid=author.aid;
then you do $result=mysql_fetch_array($sql);
how do you access author.name?
$result[name] is the one that came first, and thats topic.name. but whered author.name go?
also, i just thought of these two things. one, why is it WHERE topic.aid=author.aid instead of WHERE topic.aid==author.aid?
and, why do you say WHERE bla blah AND bla bla instead of WHERE bla bla, bla bla?