我想从数据库中显示数据到引导程序中的这些input-group-addon
组件。这些input-group-addon
文本框已被禁用。我将只使用它们来显示数据库中的数据。然后,用户只需从此处选择他们的请求。
如您所见,突出显示的部分(TrimmingIt是修剪过程)是数据库中的一个数据。 应位于文本框内。这是我的代码。谢谢。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head
content must come *after* these tags -->
<title>Request Service|CRB</title>
<!-- Bootstrap -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media
queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js">
</script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">
</script>
<![endif]-->
</head>
<body>
<?php include 'header.php' ?>
<ul class="nav nav-tabs">
<li role="presentation"><a href="index.php">Home</a></li>
<li role="presentation"><a href="trucks.php">Trucks</a></li>
<li role="presentation"><a href="suppliers.php">Suppliers</a></li>
<li role="presentation"><a href="clients.php">Clients</a></li>
<li role="presentation"><a href="services.php">Services</a></li>
<li role="presentation"><a href="accountspayables.php">Uploaded Files</a>
</li>
<li role="presentation"><a href="maintenance.php">Maintenance</a></li>
<!-- DROPDOWN start -->
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button"
aria-haspopup="true" aria-expanded="false">
About us <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li role="presentation"><a href="contactus.php">Contact us</a></li>
<li role="presentation" class="active"><a href="aboutus.php">About us</a>
</li>
</ul>
</li>
<!-- END OF DROPDOWN -->
<li class="pull-right"><a href="login.php"><span class="glyphicon glyphicon-
user" aria-hidden="true"></a></li>
</ul>
<!-- end of HEADER -->
<br>
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-2"></div>
<div class="col-sm-8">
<h1 class="text-primary">Request Service</h1>
<?php
//FETCH DATA FROM DB TO INPUT-GROUP-ADDON
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<div class='input-group'>";
echo "<span class='input-group-addon'>";
echo " <input type='submit' aria-label='...' value='Request'>";
echo "</span>";
echo "<input type='text' disabled class='form-control' aria-label='...'
value=' <?php echo '".$result['SERVICE_NAME']."'; ?>' >";
echo "</div>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "crb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT SERVICE_NAME, SERVICE_DESC FROM services");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as
$k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
</script>
<!-- Include all compiled plugins (below), or include individual files as
needed -->
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</script>
</html>