Jump to content

Help add a drop list to <input field or change this code to a <select option?


antonyfal

Recommended Posts

I have a search function in php where the text characters are matched to characters in a tables field--- works perfectly....

I need to make the input box have a droplist of words from database, this is also easy for me to do. the problem here is there is no definitive value! the options list always outputs a blank in the url---

 

its supposed to search a matching value and then output the matching value to url...

 

Here is the droplist code:

 

 

$output['RATESTITLE']='<input class="inputbox" type="text" size="24px" name="ratestitle" value="'.$sch->filter['ratestitle'].'"  onfocus="if (this.value ==\''.$output['LANGUAGE_SEARCH_RATESTITLE'].'\') {this.value = \'\'}" />';

 

this outputs a input text box--- i want to have a droplist of options to populate this text box...

If you must know this is the third day im at it...

Link to comment
Share on other sites

You don't show how you are getting the list of values from the database or if there should be a "pre-selected" value. Here is some sample code:

 

//Run query to get all words from database
$query = "SELECT word FROM table ORDER BY word";
$result = mysql_query($query) or die(mysql_error());

//Create options
$wordOptions = '';
while($row = mysql_fetch_assoc($result))
{
    //Preselect value if it matches 'LANGUAGE_SEARCH_RATESTITLE'
    $selected = ($row['word']==$output['LANGUAGE_SEARCH_RATESTITLE']) ? ' selected="selected"' : '';
    $wordOptions .= "<option value=\"{$row['word']}\"{$selected}>{$row['word']}</option>\n";
}
$output['RATESTITLE'] = "<select class=\"inputbox\" size=\"24px\" name=\"ratestitle\">{$wordOptions}</select>";

Link to comment
Share on other sites

Thanks for the reply--- If there can be a default option then blank is 0 value

 

here is the way i check the database for matching value to text box:

 

 

function Search_ratestitle()

{

$filter=$this->filter['ratestitle'];

$this->makeOrs('profile_uid');

$profile_ors=$this->ors;

if(!empty($filter) && $profile_ors )

{

$keywords= mysql_real_escape_string($filter);

$titlewords = explode( ' ', $keywords );

$titles = array();

foreach ($titlewords as $titleword)

{

$titles2[] = "LOWER(rate_title) LIKE '%$titleword%'";

$titles[] = implode( ' OR ', $titles2 );

}

$title = '(' . implode( ($magic == 'all' ? ') AND (' : ') OR ('), $titles ) . ')';

$query="SELECT profile_uid FROM #__profiles_rates ";

$query.=" WHERE ( $title ) ";

$query.=" $profile_ors ";

$result=doSelectSql($query);

foreach ($result as $st)

{

$resultObj = new stdClass;

$resultObj->profilees_uid = $st->profile_uid;

if (!in_array($resultObj,$stit))

$stit[]=$resultObj;

}

$this->resultBucket=$stit;

}

$this->sortResult();

}

 

//profilees_uid is not a spelling mistake--

 

The word entered in to the text box (first code set)is searched and matched to  a field as above---

I want to call the list of names entered into the rate_title field into a droplist which the user uses to populate the text box (first code) if there can be a default option (it should have no value) if nothing is entered it will not be searched...

one more point of interest-- the search textbox forms an array of searches so it is an optional search value that is added-- but a must!! to have it work ;)

thanks for the quick responce, will the code you first gave me work?

regards

Tony

 

Link to comment
Share on other sites

You don't show how you are getting the list of values from the database or if there should be a "pre-selected" value. Here is some sample code:

 

//Run query to get all words from database
$query = "SELECT word FROM table ORDER BY word";
$result = mysql_query($query) or die(mysql_error());

//Create options
$wordOptions = '';
while($row = mysql_fetch_assoc($result))
{
    //Preselect value if it matches 'LANGUAGE_SEARCH_RATESTITLE'
    $selected = ($row['word']==$output['LANGUAGE_SEARCH_RATESTITLE']) ? ' selected="selected"' : '';
    $wordOptions .= "<option value=\"{$row['word']}\"{$selected}>{$row['word']}</option>\n";
}
$output['RATESTITLE'] = "<select class=\"inputbox\" size=\"24px\" name=\"ratestitle\">{$wordOptions}</select>";

 

Hey yes! NO! joie de vie //joy of life= no luck with code:(--  Can anyone else take a shot at it

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.