Jump to content

[SOLVED] Cross-table Selection


sciencebear

Recommended Posts

I'm trying to run a query. Basically, the first table is a friends system. It has a column for a user and a column his/her friend. What I want to do is select all of the friends from the second column for whenever the first column is who is logged in. I can do, this, and have no problem with it. However, with these names, I want to use them as the parameters in a different table and select every row where the information in one column matches any of the friends selected from the first table. I have an idea of how this would work, but I am not sure. Does anyone know for sure how to do this?

Link to comment
Share on other sites

Nah, it didn't work.

 

Basically, what I really need to know is this:

 

I select an array of all the different friend ids from the first table. I need to use this to select all the rows in the second table where the data from a column matches any of the ids in the array, but I don't know how to do this.

Link to comment
Share on other sites

Alright here goes.

 

Table 1-friends

col1:userid

col2:friendid

 

Table 2-post

col1:id

col2:userid

col3...

col4...

(The other two columns aren't used for selection, but they need to be selected.)

 

This is basically what I have so far:

 

($userid is supplied when logged in)

 

$row1 = mysql_query("SELECT friendid FROM friends WHERE userid = '$userid'");

$row2 = mysql_fetch_array($row1);

$row3 = mysql_query("SELECT MAX(id) FROM post WHERE userid = '$row2'");

$row4 = mysql_fetch_array($row3);

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.