Hi,
I need to get the process_id or process_name to select the reject type on the table reject_list. But I don’t know how and is it possible that after I input the process_name I will get the value then it will be use in my select query to get the reject list.
<?php
session_start();
ob_start();
date_default_timezone_set("Asia/Singapore");
error_reporting(0);
include('connection.php');
//----QUERY FOR REJECT TYPE---//
if(isset($_SESSION['process_name']) != '')
{
$process_id = $_SESSION['process_id'];
$sql_reject = ("SELECT reject_process_id, reject_acro FROM reject_list WHERE reject_process_id = '$process_id'");
echo $sql_reject;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Operator's Shift Report </title>
<head>
<link rel="stylesheet" type="text/css" href="op_report.css" />
<link rel="stylesheet" type="text/css" href="calendar.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
//----auto complete process name---//
$().ready(function() {
$("#process_name").autocomplete("get_process_list.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false
});
$("#process_name").result(function(event, data, formatted) {
$("#process_id").val(data[1]);
});
});
</script>
</head>
<body onload=document.getElementById("process_name").focus();>
<form>
<script type="text/javascript" src="calendar.js"> </script>
<div id="operators_report">
<fieldset>
<legend><h1>Operator's Shift Report</h1></legend>
<table>
<tr>
<td>Process/td>
<td><input type="text" name="process_name" id="process_name" value="" size="30"></td>
<td>Supervisor/td>
<td><input type="text" name="supervisor" id="supervisor" value="" size="30"></td>
</tr>
</table>
</fieldset>
</div>
<input type="hidden" name="process_id" id="process_id" value="" />
<input type="hidden" name="spv_id" id="spv_id" value="" />
</form>
</body>
</html>
Any help is highly appreciated.
Thank you.
I think we need more details.
-
What’s with the $_SESSION[‘process_name’]. When is it set?
You have if(isset($_SESSION[‘process_name’]) != ‘’) and use $_SESSION[‘process_id’]
-
What do you mean by:
after I input the process_name I will get the value then it will be use in my select query
The autocomplete must work independently, get values from your “get_process_list.php”.
The input will work as a simple GET request (I can see that you have no method for your form).
Now, I guess you want the autocomplete to return the name AND id so you can populate the #process_id.
After you hit the submit you’ll need to use $_REQUEST[‘process_id’] and not $_SESSION (??)
However, I never used “.result” so I’d recommend to use
$("#process_name").autocomplete("get_process_list.php", {
width: 205,
matchContains: true,
mustMatch: true,
selectFirst: false,
select: function(e, ui) {
$("#process_id").val(ui.item.id); // or ui.item.value
alert('debug: '+ui.item.id); // just for debug
}
});
Also, make a dubug with your console or with some alerts to check values.
Thank you… I will try it later…
I encountered problem in jquery:
‘1’ is null or not an object if the field process_name has no value or the letter that I’ve type has no match in the database.
Thank you
Check the autocomplete structure - http://jqueryui.com/autocomplete/#remote
For your autocomplete file:
<?php
// ...
$SqlResult = getFromSql( ... );
/*
// in the end $SqlResult should look like this
$SqlResult = array(
array( 'id' => 1, 'label' => 'lbl 1', 'value' => 'val1' ),
// ....
array( 'id' => 23, 'label' => 'lbl 23', 'value' => 'val23' ),
);
*/
echo json_encode($SqlResult);
// ...
?>
Hi newphpcoder,
What autocomplete plugin are you using (could you post the URL)? It doesn’t look like the jQuery UI one.
Hi,
I resolved my problem by this code:
<?php
ob_start();
include "connection.php";
$q = strtolower($_GET["q"]);
if ($q == '') {
header("HTTP/1.0 404 Not Found", true, 404);
}
//else (!$q) return;
else{
$sql = "select process_id, process_name from process_list where process_name LIKE '$q%'";
$rsd = mysql_query($sql);
$cnt = mysql_num_rows($rsd);
if($cnt > 0)
{
while($rs = mysql_fetch_array($rsd)) {
$pid = $rs['process_id'];
$pname = $rs['process_name'];
echo "$pname|$pid\
";
}
}
else
{
header("HTTP/1.0 404 Not Found", true, 404);
}
}
?>
Thank you
Hi,
I tried to search it to google again, but I can find the exact website that I saw before. yah it does not like the jQueryUI.
Thank you