Jump to content

need help on advanced search form


pixeltrace

Recommended Posts

guys,

 

i need help on my advanced search form

my advanced form has textfield, selectbox and checkbox

 

currently my search form only got two fields but now i was

requested to developed an advanced search form.

 

below is my advanced search form page code

<form id="form1" name="form1" method="post" action="view.php">
  <table width="473" border="0" cellspacing="4" cellpadding="0">
        <tr>
          <td width="465" valign="top">Keywords :
            <input type="text" name="textfield"></td>
        </tr>
        <tr>
          <td valign="top">Country
            :    
            <select name="ccountry">
              <option value="Afghanistan">Afghanistan</option>
              <option value="Albania">Albania</option>
              <option value="Algeria">Algeria</option>
              <option value="American Samoa">American Samoa</option>
              <option value="Andorra">Andorra</option>
              <option value="Angola">Angola</option>
              <option value="Anguilla">Anguilla</option>
              <option value="Antarctica">Antarctica</option>
              <option value="Antigua and Barbuda">Antigua and Barbuda</option>
            </select>
            <br></td>
        </tr>
        <tr>
          <td>Specialization<br>
              <select name="specialization[]" size="8" class="textfield1" multiple>
                <?
$uSql = "SELECT specialization FROM specialization ORDER by sid ASC";
$uResult = mysql_query($uSql, $connection);
if(!$uResult){
echo 'no data found';
}
else{
while($uRow = mysql_fetch_row($uResult)){
?>
                <option value="<?= $uRow[0]?>">
                <?= $uRow[0]?>
                </option>
                <?
    }    
}
?>
            </select></td>
        </tr>
        <tr>
          <td>Position Level
            <select name="level">
              <option value="javascript:;" selected>----</option>
              <?
		$uSql = "SELECT level FROM level";
		$uResult = mysql_query($uSql, $connection);
		if(!$uResult){
		echo 'no data found';
		}else{
		while($uRow = mysql_fetch_array($uResult)){
			?>
              <option value="<?= $uRow[level]?>">
              <?= $uRow[level]?>
              </option>
              <?
			}    
			}
			?>
            </select></td>
        </tr>
        <tr>
          <td>Job Type 
            <span class="text3">
            <input type="checkbox" name="jtype1" value="Permanent" >
Permanent
<input type="checkbox" name="jtype2" value="Contract" />
Contract
<input type="checkbox" name="jtype3" value="Part-Time" />
Part-Time </span></td>
        </tr>
        <tr>
          <td><input type="submit" name="Submit" value="Submit"></td>
        </tr>
      </table>
</form>

 

and below is the current code of my view page wherein

the fields that i only have is keywords and specialization

<?php
include '../admean/db_connect.php';

$cond = '';
if($_POST['specialization'] != ''){
$cond = " AND specialization = '". $_POST['specialization'] ."'";
}

        $sql = "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['keywords'] ."%'".$cond;
        $query = mysql_query($sql) OR die(mysql_error());
	//$uResult = mysql_query($uSql, $connection);
        $numRows = mysql_num_rows($query);

        if($numRows < 1){
                echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
        }else{
                while($row = mysql_fetch_array($query)){
                        echo $row['j_position'] .", ". $row['specialization'] .", ". $row['date_posted'] ." etc..etc...";
                }
        }
?>

 

 

my problem in the advanced search is

if the user selects more than 1 item in the select box

and more that 1 item in the checkbox also

 

with that, i dont know what codes do i need to add here.

 

need help on this.

 

thanks!

 

Link to comment
Share on other sites

try this as one page ok.

 

your notice the princeable ok.

 


<?php


include '../admean/db_connect.php';

$cond = '';
if($_POST['specialization'] != ''){
$cond = " AND specialization = '". $_POST['specialization'] ."'";
}


//input box for keywords called keywords

$sql1= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['keywords'] ."%'".$cond;
       $result1 = mysql_query($sql1) OR die(mysql_error());
       $row1 = mysql_num_rows($result1);

        if($row1 < 1){
               echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
       }else{
               while($row10 = mysql_fetch_array($result1)){
                       echo $row10['j_position'] .", ". $row10['specialization'] .", ". $row10['date_posted'] ." etc..etc...";
               }
       }
       
       
       // dropdown table called drop
       
    $sql2= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['drop'] ."%'".$cond;
       $result2 = mysql_query($sql1) OR die(mysql_error());
       $row2 = mysql_num_rows($result2);

        if($row2 < 1){
               echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
       }else{
               while($row20 = mysql_fetch_array($result1)){
                       echo $row20['j_position'] .", ". $row20['specialization'] .", ". $row20['date_posted'] ." etc..etc...";
               }
       }
       
       
              // check box table called chk
       
    $sql3= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['chk'] ."%'".$cond;
       $result3 = mysql_query($sql1) OR die(mysql_error());
       $row3 = mysql_num_rows($result3);

        if($row3 < 1){
               echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
       }else{
               while($row30 = mysql_fetch_array($result3)){
                       echo $row30['j_position'] .", ". $row30['specialization'] .", ". $row30['date_posted'] ." etc..etc...";
               }
       }
       
       
?>

<form id="form1"  method="POST" action=" ">

//key word query

<input type="text" name="keyword">

<br><br><br>

// select box query

<select name="drop">
             <option value="Afghanistan">Afghanistan</option>
             <option value="Albania">Albania</option>
             <option value="Algeria">Algeria</option>
             <option value="American Samoa">American Samoa</option>
             <option value="Andorra">Andorra</option>
             <option value="Angola">Angola</option>
             <option value="Anguilla">Anguilla</option>
             <option value="Antarctica">Antarctica</option>
             <option value="Antigua and Barbuda">Antigua and Barbuda</option>
           </select> 
           
           
<br><br><br>

//chk box query

<input type="checkbox" name="chk" value="Permanent" >

<input type="checkbox" name="chk" value="Contract" />

<input type="checkbox" name="chk" value="Part-Time" />


<input type="submit" name="Submit" value="Submit">


Link to comment
Share on other sites

hi,

 

how do i set this up?

because when i just copied paste this and test

 

i immediately saw all the items in my database on top

 

then the form is below.

if i made some selections on the form below

its page cannot be displayed.

 

need help please.

 

thanks!

Link to comment
Share on other sites

That was an example, did it return all that was needed to be shown using the form inputs?

 

 

<?php


include '../admean/db_connect.php';

$cond = '';
if($_POST['specialization'] != ''){
$cond = " AND specialization = '". $_POST['specialization'] ."'";
}


//input box for keywords called keywords

$sql1= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['keywords'] ."%'".$cond;
        $result1 = mysql_query($sql1) OR die(mysql_error());
        $row1 = mysql_num_rows($result1);

         if($row1 < 1){
                echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
        }else{
                while($row10 = mysql_fetch_array($result1)){
                        echo $row10['j_position'] .", ". $row10['specialization'] .", ". $row10['date_posted'] ." etc..etc...";
exit;
                }
        }
        
        
        // dropdown table called drop
        
     $sql2= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['drop'] ."%'".$cond;
        $result2 = mysql_query($sql1) OR die(mysql_error());
        $row2 = mysql_num_rows($result2);

         if($row2 < 1){
                echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
        }else{
                while($row20 = mysql_fetch_array($result1)){
                        echo $row20['j_position'] .", ". $row20['specialization'] .", ". $row20['date_posted'] ." etc..etc...";
exit;
                }
        }
        
        
               // check box table called chk
        
     $sql3= "SELECT * FROM job_ads WHERE j_position LIKE '%". $_POST['chk'] ."%'".$cond;
        $result3 = mysql_query($sql1) OR die(mysql_error());
        $row3 = mysql_num_rows($result3);

         if($row3 < 1){
                echo "<font color=\"FF0000\">Sorry, there are no matches. Please try again.</font><br />\n";
        }else{
                while($row30 = mysql_fetch_array($result3)){
       echo $row30['j_position'] .", ". $row30['specialization'] .", ". $row30['date_posted'] ." etc..etc...";
      exit;
          }
        }
        
        
?>

<form id="form1"  method="POST" action=" ">

//key word query

<input type="text" name="keyword">

<br><br><br>

// select box query

<select name="drop">
              <option value="Afghanistan">Afghanistan</option>
              <option value="Albania">Albania</option>
              <option value="Algeria">Algeria</option>
              <option value="American Samoa">American Samoa</option>
              <option value="Andorra">Andorra</option>
              <option value="Angola">Angola</option>
              <option value="Anguilla">Anguilla</option>
              <option value="Antarctica">Antarctica</option>
              <option value="Antigua and Barbuda">Antigua and Barbuda</option>
            </select> 
            
            
<br><br><br>

//chk box query

<input type="checkbox" name="chk" value="Permanent" >

<input type="checkbox" name="chk" value="Contract" />

<input type="checkbox" name="chk" value="Part-Time" />


<input type="submit" name="Submit" value="Submit">

Link to comment
Share on other sites

hi,

 

no nothing happened actually,

 

when i try to search it just goes back to the same page and all

the data from my database as in every item in the table of my database

is displayed on top.

 

is there other thing that i need to setup here?

 

need help. thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.