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
https://forums.phpfreaks.com/topic/156787-solved-cross-table-selection/
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.

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);

Archived

This topic is now archived and is closed to further replies.

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