Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

advice on the most efficent way to cross reference

Status
Not open for further replies.

EricE

IS-IT--Management
Oct 6, 2000
17
US
I am working on a project with php/mysql. I have 2 tables with the following columns:

------------------
table projects:
projectid,summary,details,author

table users:
userid,email,password,first,last
------------------

When a project is submitted into the projects table the author field references their uid from the users table.

When doing a query for projects the uid of the author is returned. What is the most efficent way to swap out the uid with the person's first and last name from users? Right now I have a getuidname($id) function that queries for id and returns the name, but that runs a query EACH time.

My projects query is simple:

mysql_query("SELECT * FROM projects WHERE author = '$_SESSON[uid]'");

Is there a way to select from the other table at the same time and get all the data in 1 shot? or maybe an array of uid's and name's?

Any advice would be great!

Thank you,

Eric Eberhardt

Eric
 
How about simply relating the tables your query?


mysql_query ("SELECT * FROM authors INNER JOIN users ON author = userid WHERE author = " . $_SESSON[uid]);

or

mysql_query ("SELECT * FROM authors, users WHERE author = userid AND author = " . $_SESSON[uid]);


Also, I'm assuming that userid is an integer column. Don't put quotes around number values that aren't going into string-type columns -- you take a performance hit.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top