我想从我的mysql中的表中绘制数据,并将数据放入自定义表中。我希望将信息作为http://gyazo.com/c6a40fcd6e4edc66f7f11650f641dae2列入表格。然而,当我尝试它时,结果非常糟糕。这是我的编码。
<?php
$servername = "#";
$username = "#";
$password = "#";
$dbname = "#";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT minecraft_user, service FROM votes";
$result = $conn->query($sql);
echo '<div class="grid-40 vote-leaderboard"> <h3><i class="fa fa-star"></i>Recent Votes</h3> <table class="top-voters"> <tbody>';
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<tr><td>' . $row[minecraft_user]. '</td><td>' . $row[service]. '</td></tr><br>';
}
} else {
echo "No recent votes!";
}
echo '</tbody>';
$conn->close();
?>
有人可以帮我这个吗?我一直在测试几个小时但没有结果。
答案 0 :(得分:0)
如果你想获得最后10个表条目,那么你应该像这样更改你的SQL查询
$sql = "SELECT minecraft_user, service FROM votes order by `minecraft_user` DESC limit 0,10";
如果您将ID添加为auto_increment
,那么
$sql = "SELECT id, minecraft_user, service FROM votes order by `id` DESC limit 0,10";