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!

Getting results by using 2 tables

Status
Not open for further replies.

stevehart808

Programmer
Nov 5, 2008
6
GB
Hi can someone shed some light on this problem I'm having please?

2 tables

SHOWS_ARCHIVE (TABLE 1)

ID
SHOW_ID
AUTHOR

SHOWS (TABLE 2)

ID

When the member logs in they are a loud to see their shows because of the $author permissions;

Code:
if ($_SESSION['MEMBER_PERM'] == "2")
					{
$author = $_SESSION['MEMBER_ID'];

$sql = mysql_query("SELECT * FROM show_archive WHERE author = $author");
					}

if ($_SESSION['MEMBER_PERM'] == "2") { $author = $_SESSION['MEMBER_ID']; $sql = mysql_query("SELECT * FROM show_archive WHERE author = $author"); }

but I want to do is see the results using the SHOWS table ID as well. ie


Code:
if ($_SESSION['MEMBER_PERM'] == "2")
					{
$author = $_SESSION['MEMBER_ID'];

$sql = mysql_query("SELECT * FROM show_archive WHERE author = $author AND show_id = `shows` id");
					}
 
I don't understand what you are after at all here.

Could you post some sample data (it can be made up) and some expected output (for your second scenario).

Cheers

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
If I am not mistaken, I dare say that you meant to say:

Need to run query involving two tables. Need to return rows from both tables using unique ID field.

If that is the case, you can use a query like so:

Code:
SELECT a.*, b.id FROM show_archive a, shows b WHERE `a.author` = $author AND b.id = a.show_id

It helps to be specific and provide
a) Sample code
b) fields you intend to match against on each table

Hope this points you in the right direction!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Hi, thanks for your reply's. I got it sorted by;

SELECT * FROM show_archive, shows WHERE show_archive.show_id = shows.id

Cheers
 
Which is kind of what I suggested except for the fact that you are not using an alias for the tables.

Good to know you got it all figured out!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top