Search Table - If's/And/Or's
Posted: Sun Sep 11, 2005 6:29 am
Hi all,
I'd like to search a table in a DB with multiple variable.
so far I have 'Left Join'ed the tables together and can do a search for a single summaryId but i'm stumped at how I could do this with multiple variable.
ie, $stockId AND/OR $linerId AND/OR $supplierId
my code looks like this at the moment...
Any asistance would be greatly appreciated. TIA, Will/
I'd like to search a table in a DB with multiple variable.
so far I have 'Left Join'ed the tables together and can do a search for a single summaryId but i'm stumped at how I could do this with multiple variable.
ie, $stockId AND/OR $linerId AND/OR $supplierId
my code looks like this at the moment...
Code: Select all
$query = "SELECT ausapapersummary.summaryId, ausapapersummary.paperCategoryId, aupapercategory.paperCategory, ausapapersummary.colloPaperName, ausapapersummary.manufacturerName, ausapapersummary.cpl, ausapapersummary.stockId, austock.stockDescription, ausapapersummary.adhesiveId, auadhesive.adhesiveDescription, auliner.linerDescription, ausapapersummary.linerId, ausapapersummary.supplierId, ausupplier.supplier FROM ausapapersummary ";
$query .="LEFT JOIN aupapercategory ON ausapapersummary.paperCategoryId = aupapercategory.papercategoryId
LEFT JOIN austock ON ausapapersummary.stockId = austock.StockId
LEFT JOIN auadhesive ON ausapapersummary.adhesiveId = auadhesive.adhesiveId
LEFT JOIN auliner ON ausapapersummary.linerId = auliner.linerId
LEFT JOIN ausupplier ON ausapapersummary.supplierId = ausupplier.supplierId WHERE ";
if ($stockId)
$query .= "ausapapersummary.stockId = '$stockId'";
if ($adhesiveId)
$query .="ausapapersummary.adhesiveId = '$adhesiveId'";
if ($linerId)
$query .="ausapapersummary.linerId = '$linerId'";