我使用此代码从数据库中检索一些数据。数据库有一列,即从 0 到 40 的数字。我从数据库的 DIV 标记中获取返回数字。我想对数字进行排序,所以
1 - 20 位于 div 标签的左侧 21 - 40 位于 div 标签的右侧 0 位于 div 标签的中间
我在想是否可以在某些特定数字上进行填充,或者哪种方式最明智?
已编辑...
谢谢各位的回答。代码相当业余,但我还不太擅长。但是数据库的返回没问题,只是每次都是0。在 div 中数字所在的左侧,这就是我想要填充一些特定数字的地方。
我希望这能澄清我的问题吗?
致以诚挚的问候 朱莉
HTML:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/my_script.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css\placing.css">
<title>Numbers</title>
</head>
<body>
<div class="topbar">
<p>Topbar</p>
</div>
<div class="talraekke" id="show">
<p>Tal</p>
</div>
<div class="content">
<p>Enter The Number</p>
<form id="myForm" action="select.php" method="post">
<input type="number" name="numbervalue">
<button id="sub">Save</button>
</form>
<span id="result"></span>
</div>
<div class="talraekke">
<p>test</p>
</div>
<div class="talraekke">
<p>test</p>
</div>
</body>
</html>
JS:
// Insert function for number
function clearInput() {
$("#myForm :input").each( function() {
$(this).val('');
});
}
$(document).ready(function(){
$("#sub").click( function(e) {
e.preventDefault(); // remove default action(submitting the form)
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info){ $("#result").html(info);
});
clearInput();
});
})
// Recieve data from database
$(document).ready(function() {
setInterval(function () {
$('#show').load('response.php')
}, 3000);
});
来自数据库的 PHP 响应
// Return data from database
$result = $conn->query("SELECT numbers FROM numbertable");
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo $row['numbers'] . '<br>';
}
最佳答案
据我了解,您应该使用这种简单的方法:
<?php
for($i=0; $i<=40; $i++)
{
echo '<div class="test">'.$i.'</div></br>';
}
?>
<style type="text/css">
.test{
background-color:#284062;
text-align:center;
color:#fff;
min-width:30px;
width:32px;
}
</style>
关于php - 填充数据库的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34185639/