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
https://forums.phpfreaks.com/topic/234702-query-help-msql-php/
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
https://forums.phpfreaks.com/topic/234702-query-help-msql-php/#findComment-1206093
Share on other sites

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.