这可能不是一个很难回答的问题。我在编写这个PHP函数时遇到了麻烦......它逐行返回行,但每次返回它们增加4。所以第一行将输出,然后是第五行,然后是第9行......
function showDatabases() {
# $_GET variables from the URL.
$database = mysql_real_escape_string($_GET['database']);
$table = mysql_real_escape_string($_GET['table']);
$mysqli = new mysqli('127.0.0.1', 'root', '', $database);
$query_one = $mysqli->query("SELECT * from $table");
$num_rows = mysqli_num_rows($query_one);
$num_fields = mysqli_num_fields($query_one);
for ($x = 0; $x < $num_rows; $x++) {
for ($c = 0; $c < $num_fields; $c++) {
$row = mysqli_fetch_row($query_one);
echo($row[$c]." ");
}
echo("<br/>");
}
}
谢谢!
答案 0 :(得分:4)
mysqli_fetch_row
获取整行并将指针移动到下一行。你应该每行只调用一次;现在你每列调用一次。
即,
for ($x = 0; $x < $num_rows; $x++) {
$row = mysqli_fetch_row($query_one);
for ($c = 0; $c < $num_fields; $c++) {
echo($row[$c]." ");
}
echo("<br/>");
}
答案 1 :(得分:0)
$query = "SELECT * from $table";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
echo $row['fieldname']." ";
}
}
我建议您在默认订单不是ID订单的情况下添加订单。