Jump to content

Using Join to return one column


ppunzi

Recommended Posts

I have two tables manufacturer and product.  The product table has a column called manufacturer that corresponds to the manufacturer id (key) I am trying to create a table with a single column that has all the rows of the product table but only returns the names from the names column and null if there is no manufacturer.  I used the following inside a case which is sending the results to a tab delimited file:

 

case 'brand': $item[brand] = mysql_query("SELECT  manufacturers.name FROM manufacturers RIGHT JOIN products ON  manufacturers.id = products.manufacturer");

 

The problem is I am receiving resource ID # error messages in the resulting tab delimited file and I am not sure if there is a problem with the usage of RIGHT JOIN or nesting it in a case statement.

 

Thanks for any help.

Link to comment
Share on other sites

Thank you for your help.  That makes sense.  I guess my next question is how do I nest that within the CASE if I need the result to be a variable - can I run the RIGHT JOIN and MYSQL_FETCH_ARRAY outside of the Case phrasing and have the result look like a variable from a table to input into the CASE statement?

Link to comment
Share on other sites

Hi

 

Yes. Something like this

 

$query = mysql_query("SELECT  manufacturers.name FROM manufacturers RIGHT JOIN products ON  manufacturers.id = products.manufacturer");

While ( $row = mysql_fetch_array($query))
{
switch (true)
{
case $row['brand'] == 'fred' :
//some code for one brand
break;
case $row['brand'] == 'burt' :
//some code for another brand
break;
}
}

 

All the best

 

Keith

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.