【发布时间】:2018-03-23 18:39:24
【问题描述】:
我有以下 HTML 标题(下面的 h6 标记),我想从下面的 PHP/SQL 查询的结果中填充它们。我已经分别完成了这两个组件,但需要从我的 PHP/SQL 查询中获取值到下面的 h6 标记中。我将如何做到这一点?
HTML:
<div class="card-body">
<h5 class="card-title m-b-40" >Company Name</h5>
<h6 style='font-weight: bold;'>Company Overview</h6>
<h6>Annual Revenue: 2,000,000,000</h6>
<h6>Employees: 150,000</h6>
<h6>Industry: xxx</h6>
<h6>Inherent Risk Industry: xxx</h6>
</div>
PHP:
<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
$id = intval($_GET['id']); //casting to int type!
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
echo '<script>console.log("Connection successful!")</script>';
}
$SELECT2 = mysqli_query($conn,"SELECT * FROM `organization` WHERE organizationId=$id");
if($SELECT2 != false)
{
while($rows2 = mysqli_fetch_array($SELECT2)){
}
}else{
echo "
<tr>
<td colspan='3'>Something went wrong with the query</td>
</tr>
";
}
<?php
【问题讨论】:
-
除非您使用 AJAX,否则您需要将 HTML 放入您的 PHP 脚本中。
-
真的会有多个组织拥有相同的
organizationId吗?为什么只需要一个while循环来处理一行? -
您在将查询结果放入 HTML 时遇到什么问题?只需
echo "<h6>Employees: {$rows2['employees']}</h6>";