我已经在这个问题上苦苦挣扎了几个星期。看,我有一个带有漂亮表的页面,在jquery的帮助下是动态的。
蓝色按钮(输入[提交]),对点击作出反应并打开右侧的其他区域。 表中的所有数据都是数据库的输出。我的数据库看起来像这样:
这是我的代码:
1
我的问题:我想要从数据库中的myActions表中获取'action',然后右键单击Blue按钮“Show Actions”进入该字段。每个操作都与现场的不同行相关联。因此,第一行的事件编号为999,我想从DB中获取该记录的操作,并将其放在右侧的字段中。如果你能帮助我,我将不胜感激。谢谢!
答案 0 :(得分:0)
请尝试以下代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>
Problem Solver
</title>
<link href="other/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<!-- -------------------upper navigation------------------------------ -->
<div class="container-fluid">
<nav id="navbar" class="navbar navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="index.html">F.A.Q</a>
</li>
<li>
<a href="tech.html">Technician</a>
</li>
<li>
<a href="da.html">Delivery Analyst</a>
</li>
</ul>
<form action="#.php" method="post" name="search_form" class="navbar-form navbar-right" >
<input type="text" class="form-control" placeholder="Search..." name="search_field">
</form>
</nav>
<!-- -----------------------RESULTS' TABLE--------------------------->
<div class="row">
<div class="col-md-9 col-lg-9 col-sm-10 col-xs-12 main myTableBlock">
<h2 class="sub-header">
Results:
</h2>
<div class="table-responsive">
<?php
$dbh = new PDO("sqlite:myDB2");
$query = $dbh->prepare("SELECT * FROM myData");
$query->execute();
$result = $query->fetchall();
echo
"<table class='table table-striped table-hover' name='results_table'>
<thead>
<tr>
<th>Incident Number</th>
<th>Type of problem</th>
<th>Subject of problem</th>
<th>Date</th>
<th>Current Status</th>
</tr>
</thead>
<tbody>"
;
foreach($result as $row)
{
echo "<tr class=".$row['ID']." >";
echo "<td>" . $row['incident_number'] . "</td>";
echo "<td>" . $row['incident_type'] . "</td>";
echo "<td>" . $row['incident_subject'] . "</td>";
echo "<td>" . $row['incident_time'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" ."<input type='submit' name='trigger' value='Show Actions' class='btn btn-primary' data-toggle='collapse' href='#collapseExample' aria-expanded='false' aria-controls='collapseExample' onclick='refreshOpenner(".$row['incident_number'].")'>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>
<!-- ---------------------------------OPENNER BLOCK --------------->
<div class="col-md-2 sidebar myOpenner col-md-pull-1 col-lg-2 col-lg-pull-1 col-sm-2 col-sm-pull-1 col-xs-2 col-xs-pull-1">
<div class="collapse" id="collapseExample">
<div class="well">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<form action="#.php" method="post">
<label id="incident_number">Incident nr.:</label>
<textarea name="actionsByTech" rows="5" cols="30" placeholder="Technician's actions:"></textarea>
<br>
<br>
<textarea name="da_description" rows="5" cols="30" placeholder="DA's description:"></textarea>
</br>
<div class=" col-md-12 text-center">
<input type="submit" class="btn btn-primary" value="Update">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- ----------------OPENNER END ------------------>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="other/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script>
$(document).ready(function(){
function refreshOpenner(incidentNr)
{
$('#incident_number').text('Incident nr.: ' +incidentNr);
}
}
</script>
</body>
</html>