Dear All,
I have problem with two value search, Please kindly see my code below:
<? require("../Dbconnect/db_connect.php");?>
<form action="./" method="get"> <table width="100%" cellpadding="0" cellspacing="0" border="0" align="center">
<tr><td width="91%" align="right">
<select name="Catid">
<option value="0" selected>All Categories</option>
<?
$cats="select * from tbljobcat order by Catname asc";
$catre=mysql_query($cats);
while($catr=mysql_fetch_array($catre)){
?>
<option value="<?=$catr['Catid']?>"><?=$catr['Catname']; ?></option><? }?>
</select>
<select name="Locid">
<option value="0" selected>All Locations</option>
<?
$locsql="select * from tbljoblocation order by Locname asc";
$locresult=mysql_query($locsql);
while($locrow=mysql_fetch_array($locresult)){
?>
<option value="<?=$locrow['Locid']?>"><?=$locrow['Locname']; ?></option><? }?>
</select></td><td width="9%" align="center"><input type="submit" name="Display" value="Display"></td></tr>
</table></form>
<?
if(($Catid==0) && ($Locid==0)){
?>
<table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd">
<tr height="27">
<td width="25%" height="27" background="../images/bar.gif"> <strong>Job Title</strong></td>
<td width="20%" background="../images/bar.gif"><strong> Company Name</strong></td>
<td width="15%" background="../images/bar.gif"> <strong>Deadline</strong></td>
<td width="10%" background="../images/bar.gif"> <strong>Category</strong></td>
<td width="20%" background="../images/bar.gif"> <strong>Location</strong></td>
</tr>
<? /*
Place code to connect to your DB here.
*/
/* Get data. */
$query = "SELECT * FROM tbljob order by Jobid desc";
$portfolio = mysql_query($query);
while($item = mysql_fetch_array($portfolio))
{
$bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7";
if($item['Jobclosedate']<date("Y-m-d")){
}else{
?>
<tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline">
<a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>">
<?
if(strlen($item['Jobtitle'])>25){ echo substr($item['Jobtitle'],0,25)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline">
<?=$item['Jobcompany']?></td><td class="tblline"> <?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline"> <?
$Catid=$item['Catid'];
$catsql="select * from tbljobcat where Catid='$Catid'";
$catresult=mysql_query($catsql);
$catrow=mysql_fetch_array($catresult);
echo $catrow['Catname']?></td><td class="tblline"> <?
$Locid=$item['Locid'];
$locsql="select * from tbljoblocation where Locid='$Locid'";
$locresult=mysql_query($locsql);
$locrow=mysql_fetch_array($locresult);
echo $locrow['Locname']?></td>
</tr>
<? }
}
?>
<tr><td height="1" colspan="6" bgcolor="#0066FF">
</td>
</tr>
</table>
<? }else{
?>
<table width="100%" cellpadding="5" cellspacing="0" border="0" align="center" class="mainbrd">
<tr height="27">
<td width="25%" height="27" background="../images/bar.gif"> <strong>Job Title</strong></td>
<td width="20%" background="../images/bar.gif"><strong> Company Name</strong></td>
<td width="15%" background="../images/bar.gif"> <strong>Deadline</strong></td>
<td width="10%" background="../images/bar.gif"> <strong>Category</strong></td>
<td width="20%" background="../images/bar.gif"> <strong>Location</strong></td>
</tr>
<? /*
Place code to connect to your DB here.
$query = "SELECT * FROM tbljob where Locid like '%".$Locid."' or Catid like '%".$Catid."';
$portfolio = mysql_query($query);
while($item = mysql_fetch_array($portfolio))
{
$bgc=($bgc=="#F7F7F7")?"#ffffff" : "#F7F7F7";
if($item['Jobclosedate']<date("Y-m-d")){
}else{
?>
<tr height="30" bgcolor="<?=$bgc?>" onMouseOver="this.bgColor='#F3F3F3';" onMouseOut="this.bgColor='';"><td class="tblline">
<a href="Jobdetail.php?Jobid=<?=$item['Jobid']?>">
<?
if(strlen($item['Jobtitle'])>35){ echo substr($item['Jobtitle'],0,35)."..."; }else{ echo $item['Jobtitle'];}?></a></td><td class="tblline">
<?=$item['Jobcompany']?></td><td class="tblline"> <?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline"> <?
$Catid=$item['Catid'];
$catsql="select * from tbljobcat where Catid='$Catid'";
$catresult=mysql_query($catsql);
$catrow=mysql_fetch_array($catresult);
echo $catrow['Catname']?></td><td class="tblline"> <?
$Locid=$item['Locid'];
$locsql="select * from tbljoblocation where Locid='$Locid'";
$locresult=mysql_query($locsql);
$locrow=mysql_fetch_array($locresult);
echo $locrow['Locname']?></td>
</tr>
<? }
}
?>
</td></tr>
<tr><td height="1" colspan="6" bgcolor="#0066FF">
</td>
</tr>
</table>
<? }?>// code
My problem is when I choose the location=All location is ok but when I choose both Values it doesn't select the right criteria that I wish.