Jump to content

Query Help MSQL & PHP


wabash

Recommended Posts

I have two queries

 

$queryColor and $queryMaintenance....  I'm able to successfully echo the following queries individually:

 


$queryColor = "SELECT actualplanttable.id,actualplanttable.common, plantcolorlinktable.plant_id, plantcolorlinktable.color_id, plantcolortable.color, plantcolortable.id
        FROM plantcolorlinktable 
    	INNER JOIN actualplanttable ON plantcolorlinktable.plant_id = actualplanttable.id
INNER JOIN plantcolortable ON plantcolorlinktable.color_id = plantcolortable.id
AND plantcolortable.color = '$color'"; 

$resultColor = mysql_query($queryColor) or die(mysql_error());

$queryMaintenance = "SELECT actualplanttable.id, actualplanttable.common, plantmaintenancelinktable.plant_id, plantmaintenancelinktable.maintenance_id, plantmaintenancetable.id, plantmaintenancetable.maintenance 
	FROM plantmaintenancelinktable
	INNER JOIN actualplanttable ON plantmaintenancelinktable.plant_id = actualplanttable.id
	INNER JOIN plantmaintenancetable ON plantmaintenancelinktable.maintenance_id = plantmaintenancetable.id
	AND plantmaintenancetable.maintenance = '$maintenance'";

$resultMaintenance = mysql_query($queryMaintenance) or die(mysql_error());

 

Now, I'm looking to only echo the plants that are both = to $resultColor and $resultMaintenance

 

I.E.  I now get results for several plants that are "yellow" and several plants that are "low maintenance" from these queries.  I'm looking for help to only echo results of plants that are both "yellow" and "low maintenance only".

 

Any help would be greatly appreciated!

 

Thanks  :)

 

Bill... 

 

 

Link to comment
Share on other sites

any reason why you need 2 queries?

 

test this: (no tested on mi side but should work)

$justOneQuery = "SELECT actualplanttable.id, 
                        actualplanttable.common,
                        plantcolortable.color, 
                        plantmaintenancetable.maintenance 
                  FROM actualplanttable
                         JOIN plantcolorlinktable ON plantcolorlinktable.plant_id = actualplanttable.id
                         JOIN plantcolortable ON plantcolorlinktable.color_id = plantcolortable.id
                                                   AND plantcolortable.color = '$color'
                         JOIN plantmaintenancelinktable ON plantmaintenancelinktable.plant_id = actualplanttable.id
                         JOIN plantmaintenancetable ON plantmaintenancelinktable.maintenance_id = plantmaintenancetable.id
                                                  AND plantmaintenancetable.maintenance = '$maintenance'";

Link to comment
Share on other sites

Ah thanks guys.

 

I was trying to do this earlier but couldn't find any examples of this scope and didn't know it was possible.

 

Mikosiko your code worked perfectly thanks so much for writing that up for me!

 

Thanks again! :)

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.