antonyfal Posted March 16, 2011 Share Posted March 16, 2011 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... Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 16, 2011 Share Posted March 16, 2011 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>"; Quote Link to comment Share on other sites More sharing options...
antonyfal Posted March 16, 2011 Author Share Posted March 16, 2011 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 Quote Link to comment Share on other sites More sharing options...
antonyfal Posted March 17, 2011 Author Share Posted March 17, 2011 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.