Forum Moderators: open
<script language="javascript">
$(document).ready(function(){
$("#search-form").hide();
$('.till_search').click(function(e){
e.preventDefault();
var search_ref = $("input#search").val();
var dataString = 'search='+ search_ref + '&till_search="True"';
$.ajax({
type: 'POST',
url: 'includes/process.php',
data: dataString,
cache: false,
//dataType: "json",
success: function(html) {
//DO I NEED THIS FUNCTION?
}
});
$('#search-form').dialog({
title: "Result",
draggable: false,
resizable: false,
modal: true,
autoOpen: false,
width: 280,
height: 200,
buttons: {
"Close": function() {
$(this).dialog('close');
},
}
});
$('#search-form').dialog('open');
return false;
});
});
</script>
if(isset($_POST['till_search'])){
$sql = "SELECT * FROM till_log WHERE tl_ref LIKE '%$_POST[search]%'";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
$_SESSION['search_result'] = "Result Found - Speak to Monty for more Info";
} else {
$_SESSION['search_result'] = "No Result Found - Don't Speak to Monty";
}
}
<div id="search-form" class="ui-dialog">
<p class="validateTips"><?php if (isset($_SESSION['search_result'])) { echo $_SESSION['search_result']; } ?></p>
</div>
success: function(html) {
if (html.error) {
$("#search-form").html("<div class=\"warning\">No Results Found</div>" );
} else {
$("#search-form").html("<p><span class=\"label\">Date:</span> " + html.date + "</p>" +//);
"<p><span class=\"label\">Reference:</span> " + html.ref + "</p>" + //);
"<p><span class=\"label\">Amount:</span> " + html.amount + "</p>" + //);
"<p><span class=\"label\">Detail:</span> " + html.detail + "</p>");
}
}
if ($num_rows > 0) {
$arr = array("date" => $date, "ref" => $ref, "amount" => $amount, "detail" => $detail);
echo json_encode($arr);
} else {
$arr = array("error" => "No Result Found");
echo json_encode($arr);
}
$.ajax({
type: 'POST',
url: 'includes/process.php',
data: dataString,
dataType: "json",
cache: false,
success: function(response) {
//alert (JSON.stringify(response)); //Show JSON Alert
if (response.success) {
$("#search-form").html("<p><span class=\"label\">Date:</span> " + response.date + "</p>" +
"<p><span class=\"label\">Reference:</span> " + response.ref + "</p>" +
"<p><span class=\"label\">Amount:</span> £" + response.amount + "</p>" +
"<p><span class=\"label\">Detail:</span> " + response.detail + "</p>");
} else if (resonse.multiple) {
$("#search-form").html("<div class=\"info\">Multiple Results Found<br />Please Use Advanced Search</div>" );
} else if (response.error) {
$("#search-form").html("<div class=\"warning\">No Results Found</div>" );
}
}
});
$num_rows = mysql_num_rows($result);
if ($num_rows == 1) {
while ($row=mysql_fetch_array($result)) {
$date = date("d F Y",strtotime($row['tl_date']));
$ref = $row['tl_ref'];
$in = $row['tl_in'];
$out = $row['tl_out'];
$detail = $row['tl_detail'];
}
if ($in > 0) {
$amount = $in;
} else {
$amount = $out;
}
$arr = array("success" => "true", "date" => $date, "ref" => $ref, "amount" => number_format($amount,2), "detail" => $detail);
echo json_encode($arr);
} else if ($num_rows > 1) {
$arr = array("multiple" => "true");
echo json_encode($arr);
} else {
$arr = array("error" => "true");
echo json_encode($arr);
}
$arr = array("result" => "success");
$arr = array("result" => "multiple");
$arr = array("result" => "error");