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
https://forums.phpfreaks.com/topic/233940-using-join-to-return-one-column/
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?

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

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.