填充数据库的返回值
I use this code to revieve some data from my database. The database has one column, that are numbers from 0 - 40. I get my return numbers from the database in a DIV tag. I would like to sort the numbers, so
我使用此代码来修复数据库中的一些数据。数据库有一列,它们是0到40之间的数字。我从数据库中获取DIV标记中的返回数字。我想对数字进行排序,所以
1 - 20 is going on the left side of the div tag 21 - 40 is going on the right side of the div tag 0 is going in the middle of the div tag
1 - 20正在div标签的左侧21 - 40正在div标签的右侧0正在div标签的中间
I am thinking if it is possible to put a padding on some specifik numbers, or which way is the smartest to do it?
我在想是否可以在一些特定的数字上添加填充,或者哪种方式最聪明?
EDITED...
Thanks for the answers guys. The code is quite amateur, but I am not so good at it yet. But the return of the database is ok, except there is comming a 0 everytime. In the left handside where the numbers in the div are, that is where I want to padding some specifik numbers.
谢谢你的回答。代码非常业余,但我还不是很擅长。但是数据库的返回是可以的,除了每次都有0。在div中的数字的左侧,这是我想要填充一些特定数字的地方。
I hope that clearlifies my question a little bit?
我希望能稍微澄清一下我的问题吗?
Best Regards Julie
最好的问候朱莉
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 Response from DB
来自DB的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>';
}
1 个解决方案
#1
0
As I understood you should use this simple way:
据我所知,你应该用这个简单的方法:
<?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>
更多相关文章
- 连接相关标签的最佳数据库设计
- 在for循环中生成的数字如何输出它们,就像它们的最高值是1和最低0
- 屏蔽标签的href跳转功能
- js金额数字格式化实现代码(三位加逗号处理保留两位置小数)
- javascript如何取字符串中的数字
- 密码强度正则表达式与数字[重复]
- 用原生js实现数字自相加
- HTML5绘图之Canvas标签 绘制坐标轴
- NodeJS - 解析JSON(只有字符串或数字)