Jump to content

[SOLVED] help with join


Chris.P

Recommended Posts

I have created a join between two tables that gets all of the contents from both tables into one. I now need to do this again but only list the details for a particular id that that matches the variable $bandid. I cant figure out how to go about this as I don't be able to put in ore than one WHERE statement?  ???

 

<?php
$bandid = $_GET["bandid"];
	echo "<h1>Profile for: ".$bandid."</h1><br />";

include_once  'functions.php';

loginDetails();

$query = "SELECT users.id, users.bandname, users.bio, users.history, users.discography, images.path ".
	"FROM users, images ".
	"WHERE users.id = images.id";

Link to comment
Share on other sites

First, a question: Do you understand the following sentence?

 

I cant figure out how to go about this as I don't be able to put in ore than one WHERE statement?

 

And now the answer:

 

SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
FROM users, images
WHERE users.id = images.id AND users.bandid = $bandid

or

SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
FROM users
     INNER JOIN images ON users.id = images.id
WHERE users.bandid =  $bandid

Link to comment
Share on other sites

First, a question: Do you understand the following sentence?

 

I cant figure out how to go about this as I don't be able to put in ore than one WHERE statement?

 

And now the answer:

 

SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
FROM users, images
WHERE users.id = images.id AND users.bandid = $bandid

or

SELECT user.id, user.bandname, user.bio, users.history, users.discography, images.path 
FROM users
     INNER JOIN images ON users.id = images.id
WHERE users.bandid =  $bandid

 

Thanks, yes I do understand it although I could see why you may find it hard to understand due to the typos. Apologies for that I shall check before I post in the future.

 

I did try the AND statement before you posted which did not work although I think I may have missed off the table name. The solution you suggested works fine, thanks. :)

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.