Forum Moderators: coopster
<?php
$searchkeywords = $_POST['title'];
$searchlocation = $_POST['location'];
$searchmin = $_POST['min'];
$searchmax = $_POST['max'];
$searchrole = $_POST['role'];
echo "
<strong>Job Search:</strong><br><br>
<form class='frm' method='post' action='search.php'>
Area of Expertise: <select name='title' class='title'>
<option value=''>Search all areas of HR</option>
<option value='hr generalist'>HR Generalist</option>
<option value='employee relations'>Employee Relations</option>
<option value='l&d/management development/talent management'>L&D/Management Development/Talent Management</option>
<option value='recruitment/resourcing'>Recruitment/Resourcing</option>
<option value='reward/expat/mobility'>Reward/Expat/Mobility</option>
<option value='hr systems'>HR Systems</option>
<option value='diversity'>Diversity</option>
<option value='change management/organisational development'>Change Management/Organisational Development</option>
<option value='management consultancy (HR)'>Management Consultancy (HR)</option>
<option value='payroll'>Payroll</option>
</select><br><br>
<table align='center' cellspacing='0' cellpadding='0' border='0' width='280'>
<tr><td>
salary (from): <br><select name='min' class='min'>
<option value=''>Search all</option>
<option value='15000'>15,000</option>
<option value='20000'>20,000</option>
<option value='25000'>25,000</option>
<option value='30000'>30,000</option>
<option value='35000'>35,000</option>
<option value='40000'>40,000</option>
<option value='45000'>45,000</option>
<option value='50000'>50,000</option>
<option value='55000'>55,000</option>
<option value='60000'>60,000</option>
<option value='65000'>65,000</option>
<option value='70000'>70,000</option>
<option value='75000'>75,000</option>
<option value='80000'>80,000</option>
<option value='85000'>85,000</option>
<option value='90000'>90,000</option>
<option value='95000'>95,000</option>
<option value='100000'>100,000</option>
</select>
</td><td>
salary (to): <br><select name='max' class='max'>
<option value=''>Search all</option>
<option value='15000'>15,000</option>
<option value='20000'>20,000</option>
<option value='25000'>25,000</option>
<option value='30000'>30,000</option>
<option value='35000'>35,000</option>
<option value='40000'>40,000</option>
<option value='45000'>45,000</option>
<option value='50000'>50,000</option>
<option value='55000'>55,000</option>
<option value='60000'>60,000</option>
<option value='65000'>65,000</option>
<option value='70000'>70,000</option>
<option value='75000'>75,000</option>
<option value='80000'>80,000</option>
<option value='85000'>85,000</option>
<option value='90000'>90,000</option>
<option value='95000'>95,000</option>
<option value='100000'>100,000</option>
</select>
</td></tr>
</table>
<br>
Location: <br><select name='location' class='location'>
<option value=''>Search all regions</option>
<option value='london'>London</option>
<option value='south-east'>South-East</option>
<option value='south coast'>SouthCoast</option>
<option value='south-west'>South-West</option>
<option value='east-anglia'>East-Anglia</option>
<option value='west midlands'>West Midlands</option>
<option value='east midlands'>East Midlands</option>
<option value='north west'>North West</option>
<option value='north & north-east'>North & North-East</option>
<option value='scotland'>Scotland</option>
<option value='wales'>Wales</option>
<option value='northern ireland'>Northern Ireland</option>
<option value='republic of ireland'>Republic of Ireland</option>
<option value='uk wide'>UK Wide</option>
<option value='international'>International</option>
</select><br><br>
Type of role: <br><select name='role' class='role'>
<option value=''>Search all</option>
<option value='Permanent'>Permanent</option>
<option value='Contract'>Contract</option>
<option value='Temporary'>Temporary</option>
</select><br><br>
<input type='submit' class='submit' id='submit' value='Search'>
</form>
";
?>
</div>
</div>
<?php
//Connect to mysql db
$conn = mysql_connect('', '', '');
mysql_select_db('',$conn);
//result set for the current page
$rs = mysql_query("SELECT * FROM `job_board` WHERE `mean salary` between '$searchmin' and '$searchmax' and `keywords` like '%$searchkeywords%' and `region` = '$searchlocation' and `type` = '$searchrole'");
if (mysql_num_rows($rs) == 0) {
echo "<div width='400px' align='center'><font color='#3F262E'>Sorry, currently there are no vacancies that match your criteria.<br><br>
Please try again by selecting a different set of search options or alternatively send your CV to us <span class='email'><a href='mailto: '>here</a></span><br><br>
Otherwise please call us on <strong></strong> and we can talk to you about possible roles we may be working on in the future.</font></div>";// Show message
} else {
//Loop through the result set
if($rs) {
while ($newArray = mysql_fetch_array($rs)) {
$id = $newArray['id'];
$title = $newArray['title'];
$short = $newArray['short'];
$salary = $newArray['salary'];
$type = $newArray['type'];
$loc = $newArray['location'];
$ref = $newArray['ref'];
echo "<table width='530px' class='border' cellspacing='0' cellpadding='0' border='0'><tr><td>";
echo "<table width='530px' class='subject' cellspacing='0' cellpadding='0' border='0'><tr><td align='left'>".$title. "</td><td align='right'>" .$salary."</td></tr> <tr><td align='left'>".$type." (PG " .$ref.")</td><td align='right'>".$loc."</td></tr></table>";
echo "<table class='body' width='530px' cellspacing='0' cellpadding='0' border='0'><tr><td>".$short."........</td></tr></table>";
echo "<table width='540px' class='morelink' cellspacing='0' cellpadding='0' border='0'><tr><td align='left'><a target='_blank' href=\"job-info.php?id=".$id."\">I'm interested</a></td><td align='right'><a href='mailto:cv@example.com?subject=".$title." (PG ".$ref.")'>click to respond</a></td></tr></table>";
echo "</td></tr></table><br><br>";
}
}
}
?>
[edited by: eelixduppy at 3:29 pm (utc) on Feb. 3, 2010]
[edit reason] exemplified [/edit]
$sql = "SELECT * FROM table WHERE 1"; $sel_title = mysql_real_escape_string($_POST['title']);
if(isset($sel_title) && $sel_title != "") {
$sql .= " AND `title` LIKE '%$sel_title%'";
} $rs = mysql_query($sql); $sql .= " AND `mean salary` <= $searchmax";
$sql .= " AND `mean salary` >= $searchmin";
$role_sa = '';
$role_pe = '';
$role_co = '';
$role_te = '';
switch($searchrole) {
default:
$role_sa = ' selected';
break;
case "Permanent":
$role_pe = ' selected';
break;
case "Contract":
$role_co = ' selected';
break;
case "Temporary":
$role_te = ' selected';
break;
}
...
echo "<select name='role' class='role'>
<option value=''" . $role_sa . ">Search all</option>
<option value='Permanent'" . $role_pe . ">Permanent</option>
<option value='Contract'" . $role_co . ">Contract</option>
<option value='Temporary'" . $role_te . ">Temporary</option>
</select>"; <input name='some_name' type='text' value='" . $some_variable . "'>
$form_items = array (
'firstname' => 'fname',
'lastname' => 'lname',
'email => 'email'
);
//
$where=null;
foreach ($form_items as $key=>$value) {
if (isset($_POST[$key])) {
if ($where) { $where .= ' and'; }
$where .= " $form_items[$key]='$value';
}
}
//
list($order,$limit) = get_limit_string(); // write this func.
$query = "select * from table";
if ($where) { $query .= " where $where"; }
$query .= " $order $limit";
how do i make sure that the form remembers the options selected by the user?
function stateList($nm,$value,$class) {
if (! $nm) { die("cannot create state list, no name supplied"); }
//
$class=(isset($class))?' class="'.$class.'"':'';
$list = '<select name="' . $nm . '" id="' . $nm . '"' . $class . '>
<option value="0">Select</option>';
// The previous is important with select lists, always have
// a blank/zero value
//
$result=mysql_query("select st_id,abbrev from your_states_table order by abbrev asc");
if (!$result) { die("can't get states list); }
while ($row=mysql_fetch_array($result)) {
$list .= '<option value="' . $row['st_id'] . '"';
if (isset($value) and ($value == $row['st_id'])) { $list .= ' selected'; }
$list .= '>' . $row['abbrev'] . '</option>';
}
mysql_free_result($result);
$list .= '</select>';
//
return $list;
}