Hi all,
First post, but I don't expect it will be my last...
Anyhow, I'm in a little over my head as you will see by the amount of code I am posting. Anyhow, my problem is that the user has an option of searching based on three variables, 'school type' (universities etc.), 'program type' (undergraduate etc.), and 'course type' (accounting, anthropology etc.). Now, add to this, they also preface their searches by what area they are looking, in this case, provinces of Canada.
Anyhow, I have everything wokrking fine except when the user selects 'all provinces', or if they don't select a province and it defaults to 'all provinces'. The 'school types' and 'program types' show up but not 'course types'? Based on the code I am providing can anyone tell me why (it is a lot to ask but if nayone can direct me in the right direction i will narrow the code donw and we can go from there)?
Anyhow, here it is:
$schoolVal1 = array("",'Universities','UniversityColleges','CollegesTechnicalInst','CareerColleges',
'SecondarySchools','LanguageSchools','SummerCamps');
$schoolDisp = array("".$text[184]."..",$text[177],
$text[178],$text[179],
$text[180],$text[181],
$text[182],$text[183]);
$programsValArray1 = array("","1","2","3","4","5","6","7","8","9");
$programtype = array(" ".$text[228]."..",$text[229],$text[230],$text[231],
$text[232],$text[233],
$text[234],$text[235],$text[236],$text[284]);
$query = "Select distinct Name from $tableNames[programType] order by PTID";
$result = dbQuery($query,0,100);
$count = dbNumRows($result);
$programsValArray = array("");
while($row=dbResultArray($result))
{
$programsValArray[] = $row["Name"];
}
//
$query = "SELECT LID from $tableNames[country] where DirName like '/$country_ref'";
$result = dbQuery($query,0,100);
$count = dbNumRows($result);
$r = dbResultArray($result);
$lngID = $r[0];
//
$query = "Select CName from $tableNames[courses_master] where Type = \"$type\" and CountryLangID = \"$lngID\" order by CName";
$result = dbQuery($query,0,100);
$count = dbNumRows($result);
$CourseVal = array("");
$CourseDisp = array(" Course Type..");
while($row=dbResultArray($result))
{
$CourseVal[] = $row["CName"] ;
$CourseDisp[] = $row["CName"] ;
}
//end of new addition
if(!$text[284]) $text[284] = "Secondary Programs";
if ($lngID == 0)
$query = "SELECT a.SchoolID, a.Name, a.Enhanced from $tableNames[schools] a ";
if($lngID <> 0)
$query = "SELECT a.SchoolID, a.Name,a.Enhanced, b.Name as LName,b.countrylangid FROM $tableNames[schools] a
Left JOIN $tableNames[schoolLangExt] b ON a.schoolid = b.schoolid AND b.CountryLangID='$lngID'";
$schoolVal = array(""=>"","Universities"=>"$text[177]","UniversityColleges" => "University Colleges",
"CollegesTechnicalInst"=>"$text[179]","CareerColleges"=>"$text[180]",
"SecondarySchools"=>"$text[181]","LanguageSchools"=>"$text[182]",
"SummerCamps"=>"$text[183]");
$programtype = array("$text[228]",$text[229],$text[230],$text[231],
$text[232],$text[233],
$text[234],$text[235],$text[236],$text[284]);
/* foreach($HTTP_POST_VARS as $key=>$val)
{
if($key=="type") $displayText= $text[248];
elseif($key=="PType") $displayText= $text[249];
} */
if($type)
$displayText = $text[247] . $schoolVal[$type]." ";
else
$displayText = "Schools";
//$text[248];
if($PType)
{
$PType1= $programsValArray1[array_search($PType,$programsValArray)];
if(!$PType1)
{
$PType1 = $PType;
}
if($displayText <> "Schools")
$displayText .= $text[247] ." - ". $programtype[$PType1];
else
$displayText = $programtype[$PType1];
}
else
{
if(!$displayText)
$displayText.= $text[249];
}
if($province)
$displayText.= " in ". $province;
else
$displayText.= " in Canada";
if($province || $type || $PType || $CType)
{
$query .= "WHERE ";
if($province)
$query .= "Province LIKE '$province' ";
if($province != '' && $type != '')
$query .= "AND ";
if($type)
$query .= " Type LIKE '$type' ";
if(($province != '' || $type != '') && $PType != '')
$query .= "AND ";
if($PType)
{
$PType1= $programsValArray1[array_search($PType,$programsValArray)];
if ($PType1)
$query .= " PType LIKE '%|$PType1|%' ";
else
{
$query .= " PType LIKE '%|$PType|%' ";
$PType = $programsValArray[$PType];
}
}
if($CType)
{
if($CType !="" && $type !="" )
$courseQuery = "Select CID From $tableNames[courses_master] where Type like \"$type\" and CName = \"$CType\" AND CountryLangID='$lngID'";
else if($CType != "" && $type == "" )
$courseQuery = "Select CID From $tableNames[courses_master] where CName = \"$CType\" AND CountryLangID='$lngID'";
$courseResult = dbQuery($courseQuery,0,100);
$Ccount = dbNumRows($courseResult);
if ($Ccount)
{
while($CourseRow=dbResultArray($courseResult))
{
$str .= $CourseRow[CID].",";
}
$str = Substr($str,0,strlen($str)-1);
$query = "Select a.SchoolID, a.Name, a.Enhanced From $tableNames[courses] c, $tableNames[schools] a where CID in ($str) and Province LIKE '$province' and a.SchoolID = c.SID ";
if($PType)
$query .= "and PID like \"%|$PType|%\" ";
if($lngID <> 0)
{
$LIDResult = dbQuery($query,0,100);
$LIDcount = dbNumRows($LIDResult);
if ($LIDcount)
{
while($LIDRow=dbResultArray($LIDResult))
{
$Lstr .= $LIDRow[SchoolID].",";
}
$Lstr = Substr($Lstr,0,strlen($Lstr)-1);
$query = "SELECT DISTINCT a.SchoolID, a.Name,a.Enhanced, b.Name as LName,b.countrylangid FROM $tableNames[schools] a
Left JOIN $tableNames[schoolLangExt] b ON a.schoolid = b.schoolid AND b.CountryLangID='$lngID' having a.SchoolID in ($Lstr) ";
}
}
}
}
}
$query .= "ORDER BY a.Enhanced asc, a.Name";
Let me know if i can give you any more info.
Thanks.
Rene