Jump to content

Recommended Posts

I have a search form which allows people to search a database of records, the information is coming from various tables. However, I wish to add a dropdown option.

 

let me explain the layout.

 

table name - jos_RAM_jobs

column name - "jobtype"

 

example:

job type = 1

job type = 3

 

1 = permenant

3 = contract

 

I wish to make this dropdown work with this table so that people can restrict the results

 

<select name="contract">
<option value="">Contract Type</option>
<option value="1">Permenant</option>
<option vale="3">Contract</option>
</select>

 

I have attached the file, the field I need to edit is on line 127, any ideas how I could make this work?

default.php

Edited by barryflood22

thank you, I have made adjustments to my code.

 

i now have:

 

 <select name="Contract">
   <option value="All"
<?php if ($salary=='All') { echo 'selected'; } ?> >
  Contract
   </option>

   <?php
$contractquery909="select * from jos_RAM_jobs";
$sth909=mysql_query($contractquery909);
$num_rows909 = mysql_num_rows($sth909);
// records found?
if ($num_rows909>0) {
 while ($row909=mysql_fetch_array($sth909, MYSQL_ASSOC)) {
  $jobtype=$row909['jobtype'];
  $selind909='';
  if ($salary==$bid) { $selind909='selected'; }
  echo "<option value='$jobtype'>$jobtype</option>";
 } // eof while loop
} // eof check for records found
?>
 </select>

 

its now displaying a list of number

 

1

3

1

1

3

 

and so on, but it doesnt seem to work with the search, it just shows all regardless

Without seeing the db structure, this is a guess, but in this line

 

echo "<option value='$jobtype'>$jobtype</option>";

 

You set both the value and what's displayed to the same thing, which I'm guessing is the id from the db. (If you open the page source, I'm sure you'd see the values of those option tags would be the same thing). Since your doing a 'select *', I'm sure there's a field in there that represents a name instead. Use that in place of the second instance of $jobtype.

 

But again, this is just a guess since there's not much to go on.

Edited by TOA

Okay i downloaded your file and i went through it, can you try it and see if anything changes?

 


<script type="text/javascript">

function GetLocation(str)
{
// var data = document.getElementById("sector").value;
 //alert(str);
// var locid = document.getElementById('SearchLocation').value;
if (str == "All"){
alert("Please select a Role Type");
document.getElementById("sector").focus();
document.getElementById("sector").select();
return false
//location.reload(true);
}

if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 { 
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {//alert(innerHTML=xmlhttp.responseText);
   document.getElementById("location").innerHTML=xmlhttp.responseText;
   }
 }

 xmlhttp.open("GET","http://<?php echo $_SERVER[HTTP_HOST]; ?>/dev/getLoc.php?loc="+str,true);


xmlhttp.send();
}

</script>

<?php



//get the database configuration settings
$conf =& JFactory::getConfig();
$dbhost = $conf->getValue('config.host');
$dbuser = $conf->getValue('config.user');
$dbpassword = $conf->getValue('config.password');
$dbname = $conf->getValue('config.db');
$dbprefix = $conf->getValue('config.dbprefix');





// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Check for any error message from our helper
if ($msg != '') { echo "<p>".$msg."</p>\n"; }

// display the list of sectors retrieved by our helper
?>

<p><?=$intro_para?></p>

<form method="post" action="index.php" name="searchForm">

 <p>
 <input type="hidden" name="option" value="com_recruitmentmanager" />
 <input type="hidden" name="task" value="search" />
 <input type="hidden" name="Itemid" value="<?=$Itemid?>" />
 <select name="sector" id="sector" onchange="GetLocation(this.value);" style='font-size: <?=$text_size?>;'>
   <option value="All" >Role Type</option>
   <?php
for ($n=0; $n<count($sectors); $n++) {

echo "<option value='".$sectors[$n]['id']."'>".$sectors[$n]['desc']."</option>\n";

} // eof for loop ?>
</select>
 <br />
 <span id="location">
 <select name="area" style='font-size: <?=$text_size?>;'>
   <option value="">Location</option>
   <?php
for ($n=0;$n<count($areas);$n++) {
if ($show_country) {
if ($areas[$n]['County'] != '') { 
echo "<option value='".$areas[$n]['id']."'>".$areas[$n]['Country'].', '.$areas[$n]['County']."</option>\n";
} else { 
echo "<option value='".$areas[$n]['id']."'>".$areas[$n]['Country']."</option>\n";
}
} else {
if ($areas[$n]['County'] != '') { 
echo "<option value='".$areas[$n]['id']."'>".$areas[$n]['County'] . "</option>\n";
} else { 
echo "<option value='".$areas[$n]['id']."'>".$areas[$n]['Country'] . "</option>\n";
}
}
} // eof for loop
?>
</select>
</span>
 <br />
 <select name="salary">
   <option value="All" selected="<?php if ($salary=='All') { echo 'selected'; } ?>" >Salary</option>
   <?php
// get list of rate bands
$query="SELECT * FROM ".$dbprefix."RAM_RateBands ORDER BY `display_order`, `desc` asc";
$sth=mysql_query($query);
$num_rows = mysql_num_rows($sth);
// records found?
if ($num_rows > 0) {
while ($row = mysql_fetch_array($sth)) {
$bid = $row['id'];
$desc = $row['desc'];
$selind = '';
if ($salary == $bid) { $selind = 'selected'; }
echo "<option value='$bid' $selind >".$desc."</option>";
} // eof while loop
} // eof check for records found

?>
 </select>
 <br />
 <select name="contract">
   <option value="">Contract Type</option>
  <option value="1">Permenant</option>
  <option value="3">Contract</option>

 </select>
 <br />
 or<br />
   <b><?php echo JText::_('RAM_ASSM_SEARCHFOR'); ?>:</b> 
   <input type="text" name="searchfor" size="16" value="" />
   <br /><br />
 <div style="text-align:right">
   <input type="image" src="/img/search.png" name="search" value="Search" class="btn" style="border:0" />
   </div>
 </p>

</form>

no difference, I have been working at my version and have made some progress, its not populating a list id id's under contract dropdown but it still doesnt make a difference to the search results

 

<script type="text/javascript">
function GetLocation(str)
{
// var data = document.getElementById("sector").value;
 //alert(str);
// var locid = document.getElementById('SearchLocation').value;
if (str == "All"){
alert("Plaease select a Role Type");
document.getElementById("sector").focus();
document.getElementById("sector").select();
return false
//location.reload(true);
}
if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
   {//alert(innerHTML=xmlhttp.responseText);
   document.getElementById("location").innerHTML=xmlhttp.responseText;
   }
 }
 xmlhttp.open("GET","http://<?php echo $_SERVER[HTTP_HOST]; ?>/dev/getLoc.php?loc="+str,true);
xmlhttp.send();
}
</script>
<?php

//get the database configuration settings
$conf =& JFactory::getConfig();
$dbhost = $conf->getValue('config.host');
$dbuser = $conf->getValue('config.user');
$dbpassword = $conf->getValue('config.password');
$dbname = $conf->getValue('config.db');
$dbprefix = $conf->getValue('config.dbprefix');

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Check for any error message from our helper
if ($msg!='') { echo "<p>$msg</p>\n"; }
// display the list of sectors retrieved by our helper
?>
<p><?php echo $intro_para; ?></p>
<form method="post" action="index.php" name="searchForm">
 <p>
 <input type="hidden" name="option" value="com_recruitmentmanager" />
 <input type="hidden" name="task" value="search" />
 <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
 <select name="sector" id="sector" onchange="GetLocation(this.value);" style='font-size: <?php echo $text_size; ?>;'>
   <option value="All" >Role Type</option>
   <?php
for ($n=0; $n<count($sectors); $n++) {

echo " <option value='" . $sectors[$n]['id'] . "'>" . $sectors[$n]['desc'] . "</option>\n";

} // eof for loop ?>
</select>
 <br />
 <span id="location">
 <select name="area" style='font-size: <?php echo $text_size; ?>;'>
   <option value="">Location</option>
   <?php
for ($n=0;$n<count($areas);$n++) {
if ($show_country) {
 if ($areas[$n]['County']!='') {
  echo " <option value='" . $areas[$n]['id'] . "'>" . $areas[$n]['Country'] . ', ' . $areas[$n]['County'] . "</option>\n";
 } else {
  echo " <option value='" . $areas[$n]['id'] . "'>" . $areas[$n]['Country'] . "</option>\n";
 }
} else {
 if ($areas[$n]['County']!='') {
  echo " <option value='" . $areas[$n]['id'] . "'>" . $areas[$n]['County'] . "</option>\n";
 } else {
  echo " <option value='" . $areas[$n]['id'] . "'>" . $areas[$n]['Country'] . "</option>\n";
 }
}
} // eof for loop
?>
</select>
</span>
 <br />
 <select name="salary">
   <option value="All" <?php if ($salary=='All') { echo 'selected'; } ?> >Salary</option>
   <?php
// get list of rate bands
$query="select * from ".$dbprefix."RAM_RateBands order by `display_order`, `desc` asc";
$sth=mysql_query($query);
$num_rows = mysql_num_rows($sth);
// records found?
if ($num_rows>0) {
 while ($row=mysql_fetch_array($sth, MYSQL_ASSOC)) {
  $bid=$row['id'];
  $desc=$row['desc'];
  $selind='';
  if ($salary==$bid) { $selind='selected'; }
  echo "<option value='$bid' $selind >$desc</option>";
 } // eof while loop
} // eof check for records found
?>
 </select>
 <br />
 <select name="Contract">
   <option value="All"
<?php if ($salary=='All') { echo 'selected'; } ?> >
  Contract
   </option>

   <?php
$contractquery909="select * from jos_RAM_jobs";
$sth909=mysql_query($contractquery909);
$num_rows909 = mysql_num_rows($sth909);
// records found?
if ($num_rows909>0) {
 while ($row909=mysql_fetch_array($sth909, MYSQL_ASSOC)) {
  $jobtype=$row909['jobtype'];
  $selind909='';
  if ($salary==$bid) { $selind909='selected'; }
  echo "<option value='$jobtype'>$jobtype</option>";
 } // eof while loop
} // eof check for records found
?>
 </select>
 <br />
 or<br />
   <b><?php echo JText::_('RAM_ASSM_SEARCHFOR'); ?>:</b>
   <input type="text" name="searchfor" size="16" value="" />
   <br /><br />
 <div style="text-align:right">
   <input type="image" src="/img/search.png" name="search" value="Search" class="btn" style="border:0;margin-top:-10px;" />
   </div>
 </p>
</form>

First rule: Turn on error reporting, and fix every error, warning and notice it gives you.

Second rule: Move all of the processing PHP code to the top of the document, as described in the "HEADER ERRORS" thread.

Third rule: Don't use variables without defining them, or if fetched from outside of the script provide examples of values.

Fourth rule: Use proper indexing and newlines, and in a consistent manner, to ensure full readability of your code.

Fifth rule: Comment your code.

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.