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>&nbsp;
        
        <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">&nbsp;&nbsp;<strong>Job Title</strong></td>
        <td  width="20%" background="../images/bar.gif"><strong>&nbsp;&nbsp;Company Name</strong></td>
        <td width="15%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Deadline</strong></td>
        <td width="10%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Category</strong></td>
        <td  width="20%" background="../images/bar.gif">&nbsp;&nbsp;<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">   
             &nbsp;&nbsp;<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">&nbsp;&nbsp;
               <?=$item['Jobcompany']?></td><td class="tblline">&nbsp;&nbsp;<?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline">&nbsp;&nbsp;<?
	$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">&nbsp;&nbsp;<?
	$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">&nbsp; 
             
             </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">&nbsp;&nbsp;<strong>Job Title</strong></td>
        <td  width="20%" background="../images/bar.gif"><strong>&nbsp;&nbsp;Company Name</strong></td>
        <td width="15%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Deadline</strong></td>
        <td width="10%" background="../images/bar.gif">&nbsp;&nbsp;<strong>Category</strong></td>
        <td  width="20%" background="../images/bar.gif">&nbsp;&nbsp;<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">   
             &nbsp;&nbsp;<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">&nbsp;&nbsp;
               <?=$item['Jobcompany']?></td><td class="tblline">&nbsp;&nbsp;<?=date("M d, Y",strtotime($item['Jobclosedate']));?></td><td class="tblline">&nbsp;&nbsp;<?
	$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">&nbsp;&nbsp;<?
	$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">&nbsp; 
             
             </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.

Hey,

You've posted a huge code segment but not explained what it does or why it does it? Your description is rather vauge and I, for one, don't really want to dig through all that code looking for a problem I don't know about.

Chris

Hey,

You've posted a huge code segment but not explained what it does or why it does it? Your description is rather vauge and I, for one, don't really want to dig through all that code looking for a problem I don't know about.

Chris

Thanks so much for Mr. Heenix for commenting my post.

My problem is that I can search only both values like All=location and All category is fine

But I if select Location=Phnom Penh and Category= Computer is not show me the right criteria.

Thank so much in advance for your million help.


Kindly regards,

Bunhok

Hey,

I've spotted a slight problem near the beginning of your script. The section where you loop to show the job categories writes the category ID and the category name into an option field. You have a default field named "All Categories" with the value of 0. However, in MySQL, I believe it may be possible to get an index of 0.. this would produce html like this:

<option value="0">All Categories</option>
<option value="0">Category A</option>
<option value="1">Category B</option>

I recommend you make the "All Categories" and "All Locations" values to -1, a number outside the range of what MySQL may return. This will stop any duplication problems. As I mentioned earlier, it's very difficult to read your code, so this next comment may be wildly off.

On line 33, you check to see if "All Categories" and "All Locations" has been selected and you have tailored an entire section querying the database for that, and in the corresponding else statement (Line 97), you've begun to show the HTML table code, but you've commented out everything else to do with the database from line 111 onwards?

I hope this helps,
Christopher Lord

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.