我想在点击时显示 Francis 的 ID。数据库中还有一个员工姓名和 ID 列表。因此,如果我单击 Francis 或 Ivann。在文本框(箭头)中,它将显示仅在员工姓名中指定的他/她的 ID。 :)
这也是我的代码。
<!--Create-->
<?php
include "config.php";
include "header.php";
?>
<?php
if(isset($_POST['bts'])):
if($_POST['id']!=null && $_POST['en']!=null && $_POST['date']!=null && $_POST['dp']!=null && $_POST['deduc']!=null){
$stmt = $mysqli->prepare("INSERT INTO personal(id_personal,name,date,datepaid,deduction) VALUES (?,?,?,?,?)");
$stmt->bind_param('sssss', $id, $en, $date, $dp, $deduc);
$id = $_POST['id'];
$en = $_POST['en'];
$date = $_POST['date'];
$dp = $_POST['dp'];
$deduc = $_POST['deduc'];
if($stmt->execute()):
?>
<p></p>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"></button>
<strong>Alright!</strong> Successfully added.
</div>
<?php
endif;
} else {
?>
<p></p>
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"></button>
<strong>Error!</strong> You must fill all the blanks.
</div>
<?php
}
endif;
?>
<p>
</p>
<div class="panel panel-default">
<div class="panel-body">
<form role="form" method="post">
<div class="form-group">
<label for="id">Employee ID</label>
<input type="text" class="form-control" name="id" id="id" placeholder="Enter ID"/>
</div>
<div class="form-group">
<label for="en">Employee Names</label>
<select class="form-control" id="en" name="en">
<option>Choose</option>
<?php
include("alqdb.php");
$result=mysqli_query($con, "SELECT EmpFName FROM employee");
while($row=mysqli_fetch_assoc($result)){
echo "<option>".$row["EmpFName"]."</option>";
}
?>
</select>
</select>
</div>
<div class="form-group">
<label for="date">Date</label>
<input type="date" class="form-control" name="date" id="date"/>
</div>
<div class="form-group">
<label for="dp">Date to be Paid</label>
<input type="date" class="form-control" name="dp" id="dp"/>
</div>
<div class="form-group">
<label for="sal">Salary</label>
<input type="text" class="form-control" name="sal" id="sal" placeholder="Salary"/>
</div>
<div class="form-group">
<label for="amnt">Amount</label>
<input type="text" class="form-control" name="amnt" id="amnt" placeholder="Enter Amount"/>
</div>
<div class="form-group">
<label for="deduc">Deduction</label>
<input type="text" class="form-control" name="deduc" id="deduc" value="0.00" readonly/>
</div>
<button type="submit" name="bts" class="btn btn-default">Ok</button>
</form>
<?php
include "footer.php";
?>
<!--Table-->
<?php
include "config.php";
include "header.php";
?>
<p>
</p>
<label>List of Transactions</label>
<table id="ghatable" class="display table table-bordered table-stripe" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date</th>
<th>Date to be Paid</th>
<th>Deduction</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$res = $mysqli->query("SELECT * FROM personal");
while ($row = $res->fetch_assoc()):
?>
<tr>
<td><?php echo $row['id_personal'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo date("F j, Y", strtotime($row['date'])) ?></td>
<td><?php echo date("F j, Y", strtotime($row['datepaid'])) ?></td>
<td><?php echo $row['deduction'] ?></td>
<td>
<a href="update.php?u=<?php echo $row['id_personal'] ?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a>
<a onclick="return confirm('Are you want deleting data')" href="delete.php?d=<?php echo $row['id_personal'] ?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete</a>
</td>
</tr>
<?php
endwhile;
?>
</tbody>
</table>
<?php
include "footer.php";
?>
<script type="text/javascript" src="js/jquery.js"></script>
<script language="javascript">
$("#amnt, #sal").keyup(function() {
$("#deduc").val(($("#sal").val() - $("#amnt").val()).toFixed(2));
});
</script>
最佳答案
您可以直接在员工选择框的选项中简单地构建这种功能(顺便说一句,您的代码中有 2 个结束选择标签)。无论如何,要做到这一点,您可以利用 HTML5 data 属性,如下所示:
<select class="form-control" id="en" name="en">
<option>Choose</option>
<?php
include("alqdb.php");
// ALSO ADD THE ID COLUMN TO YOUR SELECT QUERY SO YOU HAVE IT AVAILABLE TO YOU.
$result = mysqli_query($con, "SELECT EmpFName, id FROM employee");
while($row = mysqli_fetch_assoc($result)){
// YOUR OPTION SHOULD HAVE A VALUE ATTRIBUTE IF YOU WISH TO SAVE THE FORM.
// CHANGE $row["id"] TO THE APPROPRIATE NAME OF THE FIELD
// CORRESPONDING TO EMPLOYEE ID.
echo "<option value='{$row["EmpFName"]}' data-emp-id='{$row["id"]}'>";
echo $row["EmpFName"] . "</option>";
}
?>
</select>
然后在 Javascript 中(这里使用 JQuery):
<script type="text/javascript" src="js/jquery.js"></script>
<script language="javascript">
(function($) {
$(document).ready(function(){
var empName = $("#en");
var empID = $("#id");
empName.on("change", function(evt){
var eN = $(this);
var eID = eN.children('option:selected').attr("data-emp-id");
empID.val(eID);
});
$("#amnt, #sal").keyup(function() {
$("#deduc").val(($("#sal").val() - $("#amnt").val()).toFixed(2));
});
});
})(jQuery);
</script>
关于php - 选择员工姓名,他/她的 ID 将显示在 PHP 的文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39570688/
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
如果我在模型中设置验证消息validates:name,:presence=>{:message=>'Thenamecantbeblank.'}我如何让该消息显示在闪光警报中,这是我迄今为止尝试过的方法defcreate@message=Message.new(params[:message])if@message.valid?ContactMailer.send_mail(@message).deliverredirect_to(root_path,:notice=>"Thanksforyourmessage,Iwillbeintouchsoon")elseflash[:error]
我刚刚按照thebootsygempage上的安装说明进行操作在我保存并查看帖子内容之前,一切看起来都不错。这是输出在View中的样子:HeaderSubhead:似乎没有呈现任何html格式,因为它被引号或类似的东西转义了-其他人有这个问题吗?我没有在github页面或SO上看到任何问题来指出我正确的方向。除了遵循gem安装说明之外,我还没有做任何事情,但也许我错过了什么或者只是犯了一个愚蠢的错误。如果你还有什么想知道的,请尽管问。干杯 最佳答案 你需要有这样的东西,转义html: 关