gpt4 book ai didi

php - SQL 结果截断第一个结果

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:55 24 4
gpt4 key购买 nike

奇怪的系列事件。

我有一个严格用于建立数据库的网页( super 准系统)。 HTML 表单操作针对同一页面 - 使用 PHP 语句 if(isset($_POST['submit'])) 更改每次提交的内容。每次用户提交时,都会回显一个This [x] was successful added.,然后继续在页面底部显示一个表格。

表格正在显示结果,但第一个结果被截断了。

表格代码:

$host = "x";
$dbusername = "x";
$dbpassword = "x";
$db_name = "x";

mysql_connect("$host","$dbusername","$dbpassword") or die("Cannot connect to database");
mysql_select_db("$db_name") or die("Cannot select database");

// Collect Information
$query = "SELECT * FROM database";

$data = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($data);

print "<table border='1px' cellpadding='4px' cellspacing='0'><tr><th>ID</th><th>CELL 1</th><th>CELL 2</th><th>CELL 3</th><th>CELL 4</th><th>CELL 5</th><th>CELL 6</th><th>CELL 7</th><th>CELL 8</th><th>CELL 9</th><th>CELL 10</th><th>CELL 11</th><th>CELL 12</th><th>CELL 13</th><th>CELL 14</th></tr>";
while($row = mysql_fetch_array($data)){
print "<tr><td>";
print $row['index'];
print "</td><td>";
print $row['CELL 1'];
print "</td><td>";
print $row['CELL 2'];
print "</td><td>";
print $row['CELL 3'];
print "</td><td>";
print $row['CELL 4'];
print "</td><td>";
print $row['CELL 5'];
print "</td><td>";
print $row['CELL 6'];
print "</td><td>";
print $row['CELL 7'];
print "</td><td>";
print $row['CELL 8'];
print "</td><td>";
print $row['CELL 9'];
print "</td><td>";
print $row['CELL 10'];
print "</td><td>";
print $row['CELL 11'];
print "</td><td>";
print $row['CELL 12'];
print "</td><td>";
print $row['CELL 13'];
print "</td><td>";
print $row['CELL 14'];
print "</td></tr>";
}

echo "</table>";

mysql_close();

有什么想法吗?

最佳答案

在进入循环之前调用 mysql_fetch_array()
这会将结果的第一行加载到 $row 变量
在 while 循环中再次调用它时,您会用第二个结果行覆盖第一个结果行

$data = mysql_query($query) or die(mysql_error());

**$row = mysql_fetch_array($data);**

print "<table border='1px' cellpadding='4px' cellspacing='0'><tr><th>ID</th><th>CELL 1</th><th>CELL 2</th><th>CELL 3</th><th>CELL 4</th><th>CELL 5</th><th>CELL 6</th><th>CELL 7</th><th>CELL 8</th><th>CELL 9</th><th>CELL 10</th><th>CELL 11</th><th>CELL 12</th><th>CELL 13</th><th>CELL 14</th></tr>";
while($row = mysql_fetch_array($data)){

删除这一行,它也会显示第一行

关于php - SQL 结果截断第一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15960900/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com