How do this line in mysql any make and any model

how do this line in mysql any make and any model…
m.make_parent = $make AND c.model = m.ID
below…well?
currently works only if particular make and model have values…

you think if exclude
LEFT OUTER JOIN make m

			 ON m.make_parent = $make AND c.model = m.ID

in case both are any should work?

I tried but fails

	 $ttQuery = "SELECT 

	               c.*,  DATE_FORMAT(c.SYS_CREATION_DATE,'%d-%b-%y') AS creationDate, p.id as promoID

	             FROM 

				 cars c
				   
				 LEFT OUTER JOIN promo p 
				 
				 ON c.ID = p.ID 
				   
				 LEFT OUTER JOIN make m 
				 
				 ON m.make_parent = $make AND c.model = m.ID 
				 
				 $searchCondition
				 
				 ORDER BY ....................

I tried but failed… what exclude in query if $make = “” any car make?

if you are using a front end language like php, you would test for the $make value, and if it’s missing (which means "any"make) then you would exclude that from the sql

so if there is a $make, then your query should look like this –

FROM cars c LEFT OUTER JOIN promo p ON p.ID = c.ID LEFT OUTER JOIN make m ON m.ID = c.model AND m.make_parent = $make

and if there is no $make value, then your query should look like this –

  FROM cars c
LEFT OUTER 
  JOIN promo p 
    ON p.ID = c.ID 
LEFT OUTER 
  JOIN make m 
    ON m.ID = c.model

it did not work
what if put unequal “” the make…how to??? I think both required // currently works if select make/model or make alone,… it does not work if select nothing in drop downs.both “”

ON m.ID = c.model
AND m.make_parent = $make

Then you didn’t follow the direction. Check his second query above, if $make == “”, you need to run a different query.

finally worked by removing all this

LEFT OUTER JOIN make m

			 ON m.make_parent = $make AND c.model = m.ID 

this due here $searchCondition referred again the $make so disabled and worked… thks for the help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.