我正在使用以下内容: Ubuntu网络服务器,MS SQL数据库,PHP7.0
我有一个小的网页,该网页从HTML表格中的MS SQL Server(正在工作)返回数据。每行都是唯一的,并且有一个“赞”按钮。当用户单击“喜欢”按钮时,网页应使用+1值更新MS SQL字段LikedBy。通过这种方式,我可以看到收到了多少喜欢的ID。
<html>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<?php
$serverName = "192.168.18.28";
$connectionOptions = array(
"Database" => "Geo",
"Uid" => "user",
"PWD" => "password"
);
//Establishes the connection
$dbh = sqlsrv_connect($serverName, $connectionOptions);
if ($dbh === false) {
echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
exit;
}
$sql = "SELECT ID,LikedBy1 FROM Aanbest WHERE ImportDatum = '2019-02-12'";
$getResults = sqlsrv_query($dbh, $sql);
if ($getResults === false) {
echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
exit;
}
?>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>LikedBy?</th>
<th>Like</th>
</tr>
</thead>
<tbody>
<?php
while ($rows = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
?>
<tr>
<td><?php echo $rows['ID']?></td>
<td><?php echo $rows['LikedBy1']?></td>
<td><button type="button" id="like_btn" name="like_btn">Like</button></td>
</tr>
<?php
}
?>
</tbody>
</table>