I have an autocomplete field where the values are retrieved from the DB using the following code:
Code: Select all
<?php
require_once( '../../../core.php' );
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select cust_name,cust_id,id from mantis_plugin_SapData_relations_table where cust_name LIKE '%$q%' or cust_id LIKE '%$q%' LIMIT 0,45 ";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$id = $rs['id'];
$cid = $rs['cust_id'];
$cname = $rs['cust_name'];
echo "$cid $cname |$cid\n";
}
Code: Select all
function sapdata_report1($p_event, $p_project_id) {
echo "<style type=\"text/css\">@import url(" . config_get( 'path' ) . "plugins/SapData/files/jquery.autocomplete.css);</style>\n";
echo '<script type="text/javascript" src="',config_get( 'path' ) . 'plugins/SapData/files/jquery.autocomplete.js' , '"></script>' . "\n";
?>
<tr <?php echo helper_alternate_class() ?>>
<td class="category" width="30%"><span class="required">*</span>
<?php echo lang_get( 'plugin_sapdata_relation' ) ?>
</td>
<td width="70%">
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#relation").autocomplete("plugins/SapData/pages/get_relation_list.php", {
width: 500,
matchContains: true,
minChars: 3,
max: 15,
selectFirst: false
});
jQuery("#relation").result(function(event, data, formatted) {
jQuery("#relation_val").val(data[1]);
});
});
</script>
<input type="text" name="relation" id="relation" size="50" />
<input type="hidden" name="sap_relation" id="relation_val" />
</td>
</tr>
<?php
}
